【问题标题】:Next.js with Custom Express Server gives wrong content type for woff and woff2 files带有 Custom Express Server 的 Next.js 为 woff 和 woff2 文件提供了错误的内容类型
【发布时间】:2020-04-26 13:20:39
【问题描述】:

我有一个 Next.js 应用程序,我必须将它迁移到 Digital Ocean 上的新服务器,该服务器现在是专用 cpu,突然间我的字体被用作 Content-Type: text/html; charset=utf-8 并且我收到 500 错误。这以前在另一台服务器上工作,没有更改代码库。我已经尝试了很多东西,但我被难住了。

const path = require("path");
const glob = require("glob");

module.exports = {
  webpack: (config, { dev }) => {
    config.module.rules.push(
      {
        test: /\.(css|scss)/,
        loader: "emit-file-loader",
        options: {
          name: "dist/[path][name].[ext]",
        },
      },
      {
        test: /\.css$/,
        use: ["babel-loader", "raw-loader", "postcss-loader"],
      },
      {
        test: /\.s(a|c)ss$/,
        use: [
          "babel-loader",
          "raw-loader",
          "postcss-loader",
          {
            loader: "sass-loader",
            options: {
              sassOptions: {
                includePaths: ["styles", "node_modules"]
                  .map((d) => path.join(__dirname, d))
                  .map((g) => glob.sync(g))
                  .reduce((a, c) => a.concat(c), []),
              },
            },
          },
        ],
      }
    );
    return config;
  },
};

编辑:我添加了我的 next.config.js 的样子

【问题讨论】:

  • 你的 next.config.js 和 package.json 长什么样子?
  • @Edrian 我在上面添加了我的 next.config.js。我在另一个网站上仍然遇到这个问题。

标签: node.js express next.js woff woff2


【解决方案1】:

原来是 CORS 问题。我必须通过 Express.js 更新我的 CORS 策略以允许远程服务器。这为我解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 2022-10-05
    • 2018-11-28
    • 2019-03-15
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多