Skip to content

Instantly share code, notes, and snippets.

@andyvanee
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyvanee/ba69a8f8795300940706 to your computer and use it in GitHub Desktop.
Save andyvanee/ba69a8f8795300940706 to your computer and use it in GitHub Desktop.
Front-controller style static HTML

A little experiment in nginx rewrites. Any request for an actual directory within site gets served the index.html page. The client side is responsible for loading data.json from the requested directory and rendering (I'm using react). The client will also implement history management to avoid full-page refreshes.

error_page 404 /index.html;
location / {
if (-d $document_root$uri) {
rewrite ^ /index.html break;
}
}
location /admin/ {
proxy_pass http://127.0.0.1:9543;
}
.
├── Makefile
├── app
│ └── admin.py
├── bower.json
├── bower_components
│ ├── ...
├── nginx.conf
└── site
├── collections
│ ├── data.json
│ └── item-one
│ ├── data.json
│ └── ...
├── images
│ ├── data.json
│ └── ...
├── index.html
├── data.json
├── app.js
├── main.css
└── lib.min.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment