SOLVED thanks to Freakish in the comments the issue was my endpoint was using localhost:3030
instead of http://localhost:3030
Node is running on port 3030 and ionic is running in serve on port 8100 so localhost:3030
and localhost:8100
I know this is the problem and have looked for all the ways to implement and allow CORS.
I have tried everything under the sun from installing and using cors middleware to following other guides on implementing CORS. In the code below is where I tried following a guide to make a custom middleware and even that doesn't work.
Side note socket.io is working just fine.
app.use(bodyParser.urlencoded({'extended':'true'}));
app.use(bodyParser.json({ limit: '5mb' }));
// enable CORS
app.use(function( req, res, next ) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "x-requested-with, content-type");
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Max-Age", "1000000000");
if ('OPTIONS' == req.method) { res.send(200); } else { next(); }
});
io.on('connection', (socket) => {
socketIo.process(socket, io);
});
app.post('*', (req, res) => {
post.process(req, res);
});
http.listen(port, function(){
console.log('Listening on Port: ' + port);
});
Besic error I get when trying to post.
Access to XMLHttpRequest at 'localhost:3030/api/signin' from origin 'http://localhost:8100' has been blocked by CORS policy:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.