Deploying dynamic Nextjs + Nodejs application inside docker using caddy server

  caddy, docker, next.js, node.js

I am currently developing a simple portfolio app and my app structure is like this.
Nextjs/client,
Nodejs/server,
Mongodb/db

Nextjs is hosted locally on port 3001, Nodejs app on 5000. Whenever nextjs needs to fetch any api it calls nodejs application. All the things are configured inside docker. I am very new to deploying nextjs application and have recently used caddy server which has automatic https.
I am able to deploy the nextjs application statically using commands

next build
next export

The statically exported file called index.html inside out directory of nextjs application is pointed to caddy server on port 80 and 443. Statically exported app doesn’t support api routes which I recently came to know. I tried next build and next start command to generate a dynamic production build inside .next directory. The main problem is How do I point my dynamically generated nextjs application in caddy configuration inside docker container. My present caddy configuration looks like

www.example.com:443 {
 tls [email protected]
 root * /srv
 route {
   reverse_proxy /api* api-server:5000
   try_files {path} {path}/ /index.html
   file_server
   }
}

I am looking for hints especially related to proxy server.

Thank you in advance

Source: Docker Questions

LEAVE A COMMENT