Skip to content

I want to carve out API Routes #51891

Closed Answered by icyJoseph
KohnoseLami asked this question in Help
Discussion options

You must be logged in to vote

You can leverage custom page extensions:

// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
};

if (process.env.NODE_ENV === "production") {
  if (process.env.STATIC_ONLY === "true") {
    nextConfig.pageExtensions = ["page.tsx", "page.ts", "page.jsx", "page.js"];
    nextConfig.output = "export";
  } else {
    nextConfig.pageExtensions = ["api.ts", "api.js"];
  }
} else {
  nextConfig.pageExtensions = [
    "page.tsx",
    "page.ts",
    "page.jsx",
    "page.js",
    "api.ts",
    "api.js",
  ];
}

module.exports = nextConfig;

And then you can have this file structure:

.
├── README.md
├── next-env.d.ts
├── next.config.js
├── package…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@icyJoseph
Comment options

Answer selected by KohnoseLami
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants