当我在本地提升应用程序时,工作正常,但是当我尝试在生产环境中托管相同时,没有任何东西被加载。它来到index.html,但是js和css没有加载。
生产网址是 - > https://stg.abc.com/tools/forecaster。 本地网址 - > http://localhost:8081/tools/forecaster
routes.js
import React from 'react'
import {
BrowserRouter as Router,
Route
} from 'react-router-dom';
import login from './components/login';
const myTool = () => (
<Router>
<div>
<Route exact path="/tools/forecaster" component={login}/>
<Route exact path="/tools/forecaster_hs" component={login}/>
</div>
</Router>
)
export default myTool
server.js
const express = require("express");
const app = express();
const path = require('path');
const port = process.env.PORT || 8081 ;
app.use(express.static(path.join(__dirname, 'build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.listen(port);
请求到了index.html,但是js和css没有加载。 js和css文件都在浏览器中再次加载index.html文件。
正在加载的生成的index.html是
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><title>Partner's Commission Tool</title><link href="/static/css/main.9e6bed86.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/static/js/main.24508a76.js"></script></body></html>