is there a way to serve already build next js websites using express
Unanswered
Minskin posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
I want to serve a nextjs website on a subdomain of a express server
34 Replies
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
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.![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
Can you please give me a example
I couldn't get anything to work
I am too dumb
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
I'm unable to understand what you exactly need. are you pointing your subdomain to same server?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
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](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
https://nextjs.org/docs/pages/building-your-application/configuring/custom-server
Use this for custom server
Use this for custom server
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
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](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
Have you tried it out?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
Yes
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
Can you share any screenshot about the error or anything
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
Aight wait
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
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)
@Ping me for help
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
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](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
how can i do the latter
also the app folder doesnt contain the static files
css and images and shit
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
Proxy? It’s difficult to explain, but I can give you code in a few hours
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
i think i got it to run, but
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
You run the next app, rewrite or do something similar to the requests
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
yarn next start serves on a different port each time
thats the main problem
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
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](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
cant i just not use ports and just forward requests to the server
the next server
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
You can do that using nginx
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
MinskinOP
i have never used nginx
![Avatar](https://cdn.discordapp.com/avatars/755810867878297610/5ab9ece60bc14c554a7376a599d3deb3.webp?size=256)
Ping me for help
You can learn to use it then