Skip to content

Instantly share code, notes, and snippets.

@maddygoround
Last active August 24, 2020 11:09
Show Gist options
  • Save maddygoround/73f7defb172f671cd0f73ccf029f25d3 to your computer and use it in GitHub Desktop.
Save maddygoround/73f7defb172f671cd0f73ccf029f25d3 to your computer and use it in GitHub Desktop.
NodeJS Pratical

NodejS Practical!

Goal

Create a Reverse proxy server in NodeJS which should serve static site

Objective

Attendee should be able to implement reverse proxy in Nodejs. Reverse proxy shold able to serve static site. Proxy should handle the HTML Push state too.

What should proxy do

  1. Should serve static site
  2. Handle HTML Push state (should handle 404 on hard refresh for virtual path)
  3. Should be able to implement custom redirects
  4. Should be able to implement custom rewrites
  5. Should be able to implement custom headers
  6. Should accept rewrites, redirects and header rules from a config file
  7. Proxy should accept the static site directory
  8. Proxy should be able to implement CleanURLS

Test Criteria

Proxy will be tested against following static site framework

  1. ReactJS (Create react app)
  2. Hugo
  3. Plain html
  4. AngularJS

Example config file content

{
  "redirects": [
    { "source": "/old-docs/:id", "destination": "/new-docs/:id" },
    { "source": "/old", "destination": "/new", "type": 302 }
  ],

   "rewrites" : [
    { "source": "app/**", "destination": "/index.html" },
    { "source": "projects/*/edit", "destination": "/edit-project.html" }
  ],

   "cleanUrls": false,
	"dir": "/path/to/your/_site"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment