moved server starting code to run function in app