Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

340
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!