Exporting Static HTML with API routes
Unanswered
Asian black bear posted this in #help-forum
Asian black bearOP
I have
The issue I am experiencing is when I run
TL;DR it's statically putting the output from my local computer into the production build.
{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@Asian black bear I have `{output: "export"}` in my `next.config.js` file. I also have two `route.ts`s, 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.
this is what static export does. If you want your site being dynamic, you shouldn't use static export for it
@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_modulesI 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.jsAsian 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.jsafter 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