我如何添加自定义头到我的nextjs应用程序?

j2qf4p5b  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(94)

我希望添加X-机器人标签,以防止我的网站被搜索引擎索引。我在Vercel Docs中找到了一种方法
我面临的问题是如何将它与现有的配置一起注入到我的 *next. config.js * 文件中。这是文件的当前内容:

/** @type {import('next').NextConfig} */

const webpack=(config)=> {
  config.module.rules.push({
    test: /\.svg$/i,
    issuer: /\.[jt]sx?$/,
    use: ['@svgr/webpack'],
  })

  return config
}
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  webpack:webpack,
  images: {
    domains: ['images.unsplash.com','images.prismic.io'],
  },
}

module.exports = nextConfig

这些是我想添加的配置:”

module.exports = {
  async headers() {
    const headers = [];
      headers.push({
        headers: [
          {
            key: 'X-Robots-Tag',
            value: 'noindex',
          },
        ],
        source: '/:path*',
      });
    return headers;
  },
 };

如果你们中的任何一个人有一个想法,我会很感激。

f5emj3cl

f5emj3cl1#

/** @type {import('next').NextConfig} */

const webpack = (config) => {
    config.module.rules.push({
        test: /\.svg$/i,
        issuer: /\.[jt]sx?$/,
        use: ['@svgr/webpack']
    });

    return config;
};
const nextConfig = {
    reactStrictMode: true,
    swcMinify: true,
    webpack: webpack,
    images: {
        domains: ['images.unsplash.com', 'images.prismic.io'],
    },

    async headers() {
        return [
            {
                source: '/:path*',
                headers: [
                    {
                        key: 'X-Robots-Tag',
                        value: 'noindex'
                    }
                ]
            }
        ];
    }
};

module.exports = nextConfig;

相关问题