Node.js 来自create react应用程序的express serve index.html
出于特殊的Heroku目的,我需要部署一个解决方案,将所有路由重定向到react app index.htmlNode.js 来自create react应用程序的express serve index.html,node.js,reactjs,express,Node.js,Reactjs,Express,出于特殊的Heroku目的,我需要部署一个解决方案,将所有路由重定向到react app index.html $ tree -L 2 -I 'node_modules|temp|semantic|build' . ├── package.json ├── package-lock.json ├── public │ ├── favicon.ico │ ├── index.html // all requests from "redirect" express app should po
$ tree -L 2 -I 'node_modules|temp|semantic|build'
.
├── package.json
├── package-lock.json
├── public
│ ├── favicon.ico
│ ├── index.html // all requests from "redirect" express app should point to this file
│ ├── libs
│ ├── manifest.json
│ └── semantic.css
├── README.md
├── redirect // express app
│ ├── app.js
│ ├── bin
│ ├── package.json
│ ├── public
│ ├── views
│ └── yarn.lock
├── semantic.json
├── src
│ ├── appConfig.js
│ ├── assets
│ ├── components
│ ├── index.js
│ ├── index.scss
│ ├── old
│ ├── pages
│ ├── serviceWorker.js
│ └── utils
├── yarn.lock
└── yarn-error.log
重定向
目录包含express应用程序,我需要将每个请求重定向到index.html
一切正常,但在index.html中有一个env变量%PUBLIC_URL%,当我从重定向文件夹运行npm start时,该变量将失败并出现以下错误
pandemic@bar ~/foo/redirect
$ npm start
> redirect@0.0.0 start <path>\redirect
> node ./bin/www
URIError: Failed to decode param '/%PUBLIC_URL%/libs/pdfmake/pdfmake.min.js'
pandemic@bar~/foo/重定向
$npm开始
> redirect@0.0.0开始\重定向
>节点。/bin/www
URIError:未能解码参数“/%PUBLIC_URL%/libs/pdfmake/pdfmake.min.js”
如何解决这个问题
注意:我正在使用windows你不需要用你的URL替换%PUBLIC\u URL%吗?是的,如果我在根目录下运行
npm start
,则会正确替换%PUBLIC\u URL%,但当我从express应用所在的redirect
文件夹运行npm start
时,不会正确替换它