Better Static Glitch Sites

shindakun

Steve Layton

Posted on October 7, 2017

Better Static Glitch Sites

Here's a small tip that comes out of the Glitch support forums. By default Glitch will start a static web server on your ./app/ directory once it does not find a package.json file in the root of the app folder. This is not always the desired result - for instance what if the site generation is kicked off using grunt (or one of the countless other build tools) and you can't remove package.json? In a case like this, the start script in your package.json may be something related to that build or attempting to start a static server of it's own. Take the following snippet:

"scripts": {
  "build": "grunt build",
  "start": "grunt connect:server:keepalive",
  "test": "grunt test",
  "postinstall": "make build"
}
Enter fullscreen mode Exit fullscreen mode

Grunt is going try and start it's own static server but, on Glitch we're likely not able to reach that from the internet at large.

What can we do instead? Well, as luck would have it Glitch uses local-web-server as it's static web server. This allows us leave the package.json in place - so the default server won't start but, by updating the start command to be

"start": "ws --port 3000 --directory './' --forbid '/.env' --forbid '/.data' --log-format combined",
Enter fullscreen mode Exit fullscreen mode

we'll start the local-web-server on our own and leaving it accessible to the public. Make sure you do not leave off the forbid switches if you use .env or .data, it would not do to have those leak.

Finally, if your static site needs to start in a different directory just update the directory switch, for example --directory './www' and you should be good to go.

💖 💪 🙅 🚩
shindakun
Steve Layton

Posted on October 7, 2017

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Better Static Glitch Sites
glitch Better Static Glitch Sites

October 7, 2017