text 反向代理使用后端NodeJS Express创建React App Build
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 反向代理使用后端NodeJS Express创建React App Build相关的知识,希望对你有一定的参考价值。
const express = require('express');
const proxy = require('http-proxy-middleware');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, '../build')));
const backendURL = process.env.REACT_APP_BACKEND_HOST;
const options = {
target: backendURL, // target host
changeOrigin: true,
pathRewrite: {
'^/api': '/'
}
};
const customProxy = proxy(options);
app.use('/api', customProxy);
app.get('/*', function(request, response, next) {
response.sendFile(path.join(__dirname, '../build', 'index.html'));
});
const port = process.env.PORT || 3000;
app.listen({ port }, () =>
console.log(`
以上是关于text 反向代理使用后端NodeJS Express创建React App Build的主要内容,如果未能解决你的问题,请参考以下文章