Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 来自create react应用程序的express serve index.html_Node.js_Reactjs_Express - Fatal编程技术网

Node.js 来自create react应用程序的express serve index.html

Node.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

出于特殊的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 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
时,不会正确替换它