Node in Corporative Environment with NODESSPI

三世轮回 提交于 2019-12-03 17:23:03

Ok, I finally got this working. The changes needed as follow:

At the client Angular app You need to set withCredentials to true on $http requests.

$http({
        url: 'http://localhost:3000/api',
        method: 'GET',
        withCredentials: true,
        headers : {
            'Content-Type' : 'application/json',    
            }
    })

At the node server Some response headers are needed in the response. Origin cannot be '*' and you need to allow credentials. If you need to allow dynamic origins you can find a way of doing it in the CORS documentation.

//Cors options
var corsOptions = {
    origin: 'http://localhost:5001',
    optionsSuccessStatus: 200, 
    credentials: true,
}

//Express config
var app = express();
app.use ( cors(corsOptions) );
app.use ( bodyParser.json() );
app.use ( bodyParser.urlencoded( {extended: true} ) );
app.use ( cookieParser() );
app.use ( express.static( __dirname + '/public') );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!