问题描述
我正在处理一个 Expressjs/React 项目。
当我在生产模式下启动项目时,我没有将所有捆绑文件的 Content-Type 设置为 application/javascript
:main.js、.png、.ico、.ttf,而是设置为 text/plain
我认为我的中间件不正确,因为我没有设置任何 Content-Type..
const publicPath = options.publicPath || '/';
const outputPath = options.outputPath || path.resolve(process.cwd(),'build');
app.use(publicPath,express.static(outputPath));
app.get('*',(req,res) => res.sendFile(path.resolve(outputPath,'index.html')));
你认为这可行吗?
const mime = require('mime-types'); // https://www.npmjs.com/package/mime-types
/* ... */
const publicPath = options.publicPath || '/';
const outputPath = options.outputPath || path.resolve(process.cwd(),res) => {
res.setHeader('Content-Type',mime.lookup(req.path))
res.sendFile(path.resolve(outputPath,'index.html')));
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)