is there a way to serve already build next js websites using express
Unanswered
Minskin posted this in #help-forum

MinskinOP
I want to serve a nextjs website on a subdomain of a express server
34 Replies

@Minskin I want to serve a nextjs website on a subdomain of a express server

You want to host it in a
subdomain
. You can see a guide on google about using custom servers. Note: Nextjs servers are optimized, and you might have to optimize custom servers.I couldn't get anything to work
I am too dumb

I'm unable to understand what you exactly need. are you pointing your subdomain to same server?

MinskinOP
I am just using some middleware to check if a hostname startswith something and forward to request to something else
I wanna forward the request to a next js server thingy

MinskinOP
This doesn't work on built next apps
This requires a page and apps directory which would be found in uh
Some folder deep in the building directory

@Minskin This doesn't work on built next apps

Have you tried it out?

MinskinOP
Yes

Can you share any screenshot about the error or anything

MinskinOP
Aight wait

MinskinOP
$ tsx src/main.ts
/home/aj/builder-server/node_modules/next/dist/lib/find-pages-dir.js:42
throw new Error("> Couldn't find any `pages` or `app` directory. Please create one under the project root");
^
Error: > Couldn't find any `pages` or `app` directory. Please create one under the project root
at findPagesDir (/home/aj/builder-server/node_modules/next/dist/lib/find-pages-dir.js:42:15)
at initialize (/home/aj/builder-server/node_modules/next/dist/server/lib/router-server.js:71:69)
at async NextCustomServer.prepare (/home/aj/builder-server/node_modules/next/dist/server/next.js:240:28)
@Anay-208 | Ping on replies

@Minskin <@755810867878297610>

So i guess your only option is to copy the app folder into the product root. Or you can run the next server separately the proxy then request

MinskinOP
how can i do the latter
also the app folder doesnt contain the static files
css and images and shit

@Minskin how can i do the latter

Proxy? It’s difficult to explain, but I can give you code in a few hours

MinskinOP
i think i got it to run, but

You run the next app, rewrite or do something similar to the requests

MinskinOP
yarn next start serves on a different port each time
thats the main problem

You can specify a port
And how about you use nginx
To forward request from a specific domain to next js and other to express server

MinskinOP
cant i just not use ports and just forward requests to the server
the next server

You can do that using nginx

MinskinOP
i have never used nginx

You can learn to use it then