CORS or nginx proxy or interface development that cannot be solved by online cross-domain front end
Let me give you a link. This question has been fiercely answered
https://codeshelper.com/q/10.
quickly and directly using nginx proxy
in this case, it seems that we can only reverse proxy
for the time being, use JsonBird to solve it. However, there is a certain delay. Currently, we have not found a better way
CORS (Cross-Origin Resource Sharing, cross-source resource sharing) HTTP access control technology, but there is a compatibility problem.
ask the bosses to spray lightly, our front-end and front-end separate projects, running in an Express service, the code is as follows, the middleware used by the agent, http-proxy-middleware.
`var express = require ('express');
var proxyMiddleware = require (' http-proxy-middleware');
var apiHost =' http://172.16.0.249:8181';
var proxyTable = {
'/ v1mm: {
target: apiHost,
changeOrigin: true,
},
'/ preview': {
target: apiHost,
changeOrigin: true,
},
'/ download': {
target: apiHost,
changeOrigin: true,
}
};
var app = express ();
var port = 4000;
Object.keys (proxyTable) .forEach (function (context) {
var options = proxyTable [context];
if (typeof options = 'string') {
options = { target: options }
}
app.use (proxyMiddleware (options.filter | | context, options))
});
app.use (require ('connect-history-api-fallback') ());
app.use (express.static ('. / dist'));
var uri =' http://localhost:' + port;
)
var _ resolve;
var readyPromise = new Promise (function (resolve) {
_ resolve = resolve;
});
console.log ('> Starting prod server.' + uri);
)
var server = app.listen (port);
module.exports = {
ready: readyPromise,
close: function() {
server.close()
}
}; `