Deploy your sapper project nginx environment

I started playing with sapper a few weeks backs. I started with my blog When I deplyed my project, I came across many URL issues, as I am using nginx as webserver.

By spending some time on sapper export, I have got how to make it work. I have followed the followng steps.

First I exported my project using command

npm run export

Then I have got my exported files in folder sapper/export

Then I need to run the following command to start sapper server. Because i use some server routes too in my application.

npx serve __sapper__/export

We are almost ready.

Next we have to add a reverese proxy in my ngninx server block as follows.

server {
    listen 80;
    root /var/www/html/roopz-club-client/__sapper__/export;
    index index.html index.htm index.nginx-debian.html;
    location / {
      proxy_pass     http://localhost:5000;
      proxy_http_version 1.1;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        try_files $uri $uri/ =404;

Where http://localhost:5000 was where my sapper server listening to. Now the time to restart Nginx.

sudo service nginx restart


  • Roopz © 2020