fixed CORS problem by adding app.use(cors()); and app.options('*', cors());. Also removed a lot of extra code