He usado la siguiente guía para implementar en el servidor:
https://steveholgado.com/nginx-for-nextjs/
Los enrutadores API funcionan bien en cartero y comienzan localmente con el comando "próximo inicio" o "próximo inicio-local" .
Estructura de carpetas:
Pages ---api/ ------/redirect ---------------/index.js ---homeeste es mi código next.config.js:
require("dotenv").config(); const webpack = require("webpack"); const withPlugins = require("next-compose-plugins"); const withCss = require("@zeit/next-css"); let pathBaseDomain = process.env.API_URL_OTP; if (process.env.NODE_ENV === "production") { if (typeof window !== "undefined") { pathBaseDomain = window._env_.API_URL_OTP; } else { pathBaseDomain = process.env.API_URL_OTP; } } const nextConfig = { // target: "serverless", webpack(config) { config.module.rules.push({ test: /\.(png|svg|eot|otf|ttf|woff|woff2|gif)$/, use: { loader: "url-loader", options: { limit: 8192, publicPath: "/_next/static/", outputPath: "static/", name: "[name].[ext]" } } }); config.plugins.push(new webpack.EnvironmentPlugin(process.env)); return config; }, assetPrefix: process.env.NODE_ENV === 'production' ? pathBaseDomain : '', publicRuntimeConfig: { basePath:process.env.NODE_ENV === 'production' ? pathBaseDomain : '', }, }; module.exports = withPlugins([[withCss]], nextConfig);