I’m currently attempting to deploy my Next.js SSG application to the same droplet that my backend graphql api is hosted on. The api sits at /graphql while the app sits at /app but when I navigate to /app I get a loading… page with console showing the server is “404"ing the page.

I’m not getting any errors on the Next.js side of npm run build and npm start or with pm2 in actually starting the website. It’s clearly pulling from the next.js app as some of the resources its failing to grab are _app.js which is the root file for my next.js app.

I thought it might be an environmental variable thing but I have the same next.config.js file as my local version on the server and my local version works in both dev and production mode.

Any help on this would be greatly appreciated.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Solved the problem it turns out that I hadn’t properly set up the express server to operate on the correct root it was / and it should’ve been replaced with /api

Hi there @milorue,

Can you share the exact Nginx Server block that you are using for your setup? I could then try to advise you further.

Also what I could suggest is checking your Nginx error log for any errors that could provide you with more information:

  • tail -100 /var/log/nginx/error.log

Regards,
Bobby

  • 2020/09/11 02:27:03 [error] 71587#71587: *21018 connect() failed (111: Connection refused) while connecting to upstream
    

    while running a GET /app HTTP/1.1 i.e the application’s endpoint in nginx is example.com/app and it loads my loading page that displays when the server isn’t loading stuff so the endpoints at /graphql and /refresh_token must not be responding to internal things.

    • Hello,

      It looks like the reverse proxy for the /graphql endpoint is unable to connect to your backend service.

      You need to make sure that the reverse proxy is set to use the correct backend service and you need to make sure that the backend service is up and running.

      Regards,
      Bobby

      • When I access the /graphql endpoint everything works fine its when I try to access the /app where the frontend sits that I run into issues

        The graphql backend service sits at location / on port 8000 while the frontend sits at /app on port 3000 would it matter that the graphql endpoint is an express server?

      • I swapped around my file so now I fixed the frontend but the backend isn’t displaying now with frontend at root / and backend at /api but /api/graphql doesn’t work now, is there a better way to go about this?

Submit an Answer