engine-x
EnGINe-X, nginx the node version, the reverse proxy for node.
engine-x
is the subset of nginx, and only cares about the things inside the server
directive of nginx, and does not care about:
listen
server_name
supported directives
- location
- rewrite
- root
- proxy_pass
Install
$ npm install engine-x --save
nginx.Router
const Router } = const router = routes: // The matching priority of locations follows the // same as `location /app {...}` directive of nginx. location: '/app' // `root` could be a path or an array of paths, as well as below. root: '/path/to' // same as `location = /app/legacy {...}` directive of nginx location_is: '/app/legacy' root: '/legacy/path/to' // same as `location ~* -[a-z0-9]{7}\.png$/` directive of nginx location: /-[a-z0-9]{7}\.png$/i // rewrite '/path/to/a-28dfeg0.png' -> '/path/to/a.png' { return url } // Location could be a function pathname === '/favicon.ico' root: '/icon' // if no location matched, then use default root root: '/path/to/default/root' // if no location is matched, // and if no root specified, or no matched file found within root, // then will proxy pass to the server proxy_pass: 'http://domain.com' router// will not be called
Directives
root
Could be a path or an array of paths
rewrite(url, redirect)
- url
URL
url to be rewritten - redirect
function(redirect_url, is_permanent)
nginx
rewrite {pattern} {url_rewritten} {last};
- use
if
condition of javascript to handlelast
orbreak
flag of nginx - the return value of
rewrite(url)
is asurl_rewritten
if functionredirect
not called
redirect
flag
nginx nginx
rewrite {pattern} {redirect_url} redirect;
rewrite
{ }
permanent
flag
nginx rewrite {pattern} {redirect_url} permanent;
rewrite
{ // set `is_permanent` to `true` }
Events
'not-found'
'found'
'error'
'redirect'
'return'
'proxy-pass'
License
MIT