Currently I built API server at HTTPS together with mobile and website. The front-ends mobile(ionic web/mobile) with port 8100 is working with the API HTTPS. But when it comes to angular web with port 9999, the API HTTPS doesn't work so well, but running API server at localhost:8888 work like a charm.
ExpressJS
var cors = require('cors');
var http = require('http');
var app = express();
var server = http.createServer(app);
var port = process.env.PORT || 3000; // Always running at port 8888
app.use(cors());
Request Header
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-US,en;q=0.8
Authorization: (Some long string here)
Cache-Control:max-age=0
Connection:keep-alive
Host: api.web.com
Origin: http://localhost:9999
Problem
I don't have issue using POST API to server before user authorization. After I stored access token on Authorization header and direct to dashboard, every methods of API calls (GET,PUT,POST) returns 400 BAD REQUEST.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9999' is therefore not allowed access. The response had HTTP status code 400.