[英]express-http-proxy proxy to react js app, but get no content
The proxy port is at 8080, and want to forward to the react js website when the browser calls localhost:8080/admintool. 代理端口位于8080,并且要在浏览器调用localhost:8080 / admintool时转发到react js网站。 I am trying to use express-http-proxy to do it, but it only appears the title on the web page, but no content appears on the browser.
我正在尝试使用express-http-proxy来执行此操作,但是它仅在网页上显示标题,而在浏览器上没有内容。
The code is following: 代码如下:
const express = require('express')
const proxy = require('express-http-proxy');
const http = require('http')
const app = express();
app.use('/admintool', proxy('localhost:2000'));
http.createServer(app).listen(8080, () => console.log('proxy server listening on port 8080!'));
And, the developer console also has two errors: 并且,开发者控制台也有两个错误:
GET http://localhost:8080/static/js/bundle.js 404 (Not Found) admintool:1
GET http:// localhost:8080 / static / js / bundle.js 404(未找到)admintool:1
Refused to execute script from ' http://localhost:8080/static/js/bundle.js ' because its MIME type
拒绝从' http:// localhost:8080 / static / js / bundle.js '执行脚本,因为其MIME类型
('text/html') is not executable, and strict MIME type checking is enable ('text / html')不可执行,并且启用了严格的MIME类型检查
If I use http://localhost:2000 , the web app can display normally. 如果我使用http:// localhost:2000 ,则网络应用程序可以正常显示。 I am not sure why I am only able to get the title on the browser "React App" but not the content.
我不确定为什么我只能在浏览器“ React App”上获得标题,而不能在内容上获得。 Please help, thank a lot.
请帮忙,非常感谢。
Do you have react-router in your application? 您的应用程序中是否有react-router? If you do then remember to add
basename='admintools'
in your Router
component at root. 如果这样做,请记住在根目录的
Router
组件中添加basename='admintools'
。 Otherwise it doesn't render with BrowserRouter
. 否则,它不会使用
BrowserRouter
呈现。
let's say you have a <Route path='/examples' component={Example}/>
component. 假设您有一个
<Route path='/examples' component={Example}/>
组件。 Without the basename
props in Router
, BrowserRouter won't be able to match it when you do localhost:3000/admintools/examples
. 如果在
Router
没有basename
属性,那么当您执行localhost:3000/admintools/examples
时,BrowserRouter将无法与之匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.