create-react-app与节点快速获取%PUBLIC_URL%

我正在尝试使用快递服务器创build反应应用程序。 设置服务器后,当我点击要求,我越来越

GET http://localhost:3333/%PUBLIC_URL%/favicon.ico 400 (Bad Request)

在错误预览它给我

 URIError: Failed to decode param '/%PUBLIC_URL%/favicon.ico' at decodeURIComponent (<anonymous>) at decode_param (/home/owaishanif/code/flashcard-app/node_modules/express/lib/router/layer.js:172:12) at Layer.match (/home/owaishanif/code/flashcard-app/node_modules/express/lib/router/layer.js:123:27) at matchLayer (/home/owaishanif/code/flashcard-app/node_modules/express/lib/router/index.js:574:18) at next (/home/owaishanif/code/flashcard-app/node_modules/express/lib/router/index.js:220:15) at jsonParser (/home/owaishanif/code/flashcard-app/node_modules/body-parser/lib/types/json.js:103:7) at Layer.handle [as handle_request] (/home/owaishanif/code/flashcard-app/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/owaishanif/code/flashcard-app/node_modules/express/lib/router/index.js:317:13) at /home/owaishanif/code/flashcard-app/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/home/owaishanif/code/flashcard-app/node_modules/express/lib/router/index.js:335:12) 

这是服务器代码

 var express = require('express'); var bodyParser = require('body-parser'); var path = require ('path'); var data = {}; express() .use(express.static(path.resolve(__dirname, '..', 'public'))) .use(bodyParser.json()) .get('/api/data', (req, res) => res.json(data)) .post('/api/data', (req, res) => res.json(data = req.body)) .get('*', (req, res) => res.sendFile( path.resolve( __dirname, '..', 'public/index.html'))) .listen(3333, function(){ console.log('server running at 3333'); }); 

我想使用服务器创build反应的应用程序。 网上有文章,但已经过时了。 帮助提示和技巧是受欢迎的。

我已经解决了这个使用create-react-app build来创build一个build文件夹, %public_url% string被幕后的一些纱线脚本replace。 所以我们不能直接提供该文件夹,而是必须生成使用构build。

使用yarn buildnpm run build来生成包含asset manifest和其他文件的构build文件夹。

之后,使用该生成文件夹静态服务器的文件供生产使用。