Next.js Discord

Discord Forum

is there a way to serve already build next js websites using express

Unanswered
Minskin posted this in #help-forum
Open in Discord
Avatar
MinskinOP
I want to serve a nextjs website on a subdomain of a express server

34 Replies

Avatar
@Minskin I want to serve a nextjs website on a subdomain of a express server
Avatar
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
Avatar
I'm unable to understand what you exactly need. are you pointing your subdomain to same server?
Avatar
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
Avatar
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
Avatar
MinskinOP
Yes
Avatar
Can you share any screenshot about the error or anything
Avatar
MinskinOP
Aight wait
Avatar
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
Avatar
@Minskin <@755810867878297610>
Avatar
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
Avatar
MinskinOP
how can i do the latter
also the app folder doesnt contain the static files
css and images and shit
Avatar
@Minskin how can i do the latter
Avatar
Proxy? It’s difficult to explain, but I can give you code in a few hours
Avatar
MinskinOP
i think i got it to run, but
Avatar
You run the next app, rewrite or do something similar to the requests
Avatar
MinskinOP
yarn next start serves on a different port each time
thats the main problem
Avatar
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
Avatar
MinskinOP
cant i just not use ports and just forward requests to the server
the next server
Avatar
You can do that using nginx
Avatar
MinskinOP
i have never used nginx
Avatar
You can learn to use it then