Next.js Discord

Discord Forum

Can this proxy system be used in next js?

Unanswered
Schneider’s Smooth-fronted Caima… posted this in #help-forum
Open in Discord
Schneider’s Smooth-fronted CaimanOP
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    port: 3000,
    proxy: {
      "/api": {
        target: "http://localhost:5000",
      },
    },
  },
});

40 Replies

@Schneider’s Smooth-fronted Caiman ^^
Schneider’s Smooth-fronted CaimanOP
@jason https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites will let you do this
Schneider’s Smooth-fronted CaimanOP
this crashes my server
incase it has to be inside nextConfig
Schneider’s Smooth-fronted CaimanOP
/** @type {import('next').NextConfig} */

export default {
  async rewrites() {
    return [
      {
        source: "/api",
        destination: "http://localhost:5000",
      },
    ];
  },
};

okk got it working but it isnt hitting the server
Schneider’s Smooth-fronted CaimanOP
Schneider’s Smooth-fronted CaimanOP
Tried thar
Still didn't work
@Schneider’s Smooth-fronted Caiman Still didn't work
Clarify. What happened? 404 again?
Schneider’s Smooth-fronted CaimanOP
yep
export default {
  async rewrites() {
    return [
      {
        source: "/api/:path*",
        destination: "http://localhost:5000/api/:path*",
      },
    ];
  },
};
also for somereason i had the config file in .mjs
so i made another one
with js and added this in there
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;

this is my mjs one
No, only use one of them. Copy the content of .js to .mjs, delete .js
Schneider’s Smooth-fronted CaimanOP
it doest work thats the problem
wait
even i remove
the export and const
it still doesnt work
Remove the const nextConfig, the comment above it, and the export default nextConfig
Schneider’s Smooth-fronted CaimanOP
does the comment affect anything?
like how?
🤔
i did this but now i dont get the 404 but nothing happes the is not being sent only
@joulev What do you mean?
Schneider’s Smooth-fronted CaimanOP
i dont see any get post or any logs
Well that doesn’t make it any clearer to me what’s going on…
@joulev Well that doesn’t make it any clearer to me what’s going on…
Schneider’s Smooth-fronted CaimanOP
okk i figured everything out can u just tell me what is the differnce in js and mjs
Schneider’s Smooth-fronted CaimanOP
i assume its module js and js?
Schneider’s Smooth-fronted CaimanOP
got it thanks