Search code examples
javascriptreactjsstaticnext.jsserve

Nex.js static file serve with the extension without downloading


I need to serve the stellar.toml file in domain/.well-known/stellar.toml and the content type needs to be text/plain. I tried adding the next config like this and it works only if stellar file is saved without an extension.

I need to serve the content at the domain/.well-known/stellar.toml not at the domain/.well-known/stellar

module.exports = {
  async headers() {
    return [
      {
        source: "/.well-known/stellar",
        headers: [
          {
            key: "Content-Type",
            value: "text/plain",
          },
        ],
      },
    ];
  },
};

Solution

  • You should probably add the toml extension in the webpack configuration in NextJs. https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config