DEV Community

Cover image for Better Static Glitch Sites
Steve Layton
Steve Layton

Posted on • Originally published at on

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"

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",

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.

Top comments (0)