Next.js Discord

Discord Forum

Exporting Static HTML with API routes

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
I have {output: "export"} in my next.config.js file. I also have two route.tss, with each their own URL route, of course.

The issue I am experiencing is when I run npm run build and deploy the output on an nginx server. When I build, it appears that nextjs is hitting the two routes (on my local computer), storing what they return, and then bundling that into the output. This leads to the production website having exactly what my local computer has, but I don't want that. I want it to dynamically run the code on the server.

TL;DR it's statically putting the output from my local computer into the production build.

16 Replies

Asian black bearOP
For example, I have an API route called /api/catalog. It made a catalog.body file and seems to be statically using that instead of running the catalog/route.ts file
@Ray this is what static export does. If you want your site being dynamic, you shouldn't use static export for it
Asian black bearOP
Is there no way to accomplish that and use html files?
@Asian black bear Is there no way to accomplish that and use html files?
nope, will need a node server
@Ray nope, will need a node server
Asian black bearOP
Would {output: "standalone"} work?
I just can't use the node server because my VPS doesn't have enough storage to hold node_modules
I had to do npm i next and it took like 10% of my disk space
@Asian black bear Would `{output: "standalone"}` work?
yes and start the server with node .next/standalone/server.js
Asian black bearOP
Do I need next installed?
If I could uninstall it due to the large disk space it uses, that would be great
@Asian black bear Do I need `next` installed?
no, you should be able to copy .next/standalone folder to it and start with server.js
after you build
Asian black bearOP
Amazing, thanks, that worked!
How can I change port from 3000 to 80 though?
@Asian black bear How can I change port from `3000` to `80` though?
PORT=80 node .next/standalone/server.js