微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ExpressJS text/plain Content-type to main.azkjnearjs

如何解决ExpressJS text/plain Content-type to main.azkjnearjs

我正在处理一个 Expressjs/React 项目。
当我在生产模式下启动项目时,我没有将所有捆绑文件的 Content-Type 设置为 application/javascript:main.js、.png、.ico、.ttf,而是设置为 text/plain

我捆绑的 main.js 示例:

enter image description here

我认为我的中间件不正确,因为我没有设置任何 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 举报,一经查实,本站将立刻删除。