Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

332
Visualizações
Next.js API Routes get result 404 not found when deployment to the server

I have used the guide below to deploy to the server:

https://steveholgado.com/nginx-for-nextjs/

API Routers working well in postman and start local with command "next start" or "next start-local" .

Folder Structure:

Pages
---api/
------/redirect
---------------/index.js
---home

this is my next.config.js code:

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);
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda