HTTP dispatcher
This is an http dispatcher
Install
npm install http-dispatcher
Example
Main file: app.js
"use strict"; var dispatcher = require('http-dispatcher'); var urls = require('./url.json'); var PORT = 5001; dispatcher.initialize(urls);dispatcher.create(PORT); console.log("Server listening on port " + PORT);
File: url.json
{ "get" : [ { "file": "/", "path": "/var/www/html/demo/index.html", "mime": "text/html" }, { "file": "/index", "path": "/var/www/html/demo/index.html", "mime": "text/html" }, { "file": "/index.html", "path": "/var/www/html/demo/index.html", "mime": "text/html" }, { "file": "/style.css", "path": "/var/www/html/demo/style.css", "mime": "text/css" } ], "post" : [ { "file": "/index", "path": "/var/www/html/demo/index.html", "mime": "text/html" } ]}
File: index.html
Page TitleHello world
File: style.css
body { background-color: yellow;}
Run
node app.js
Type on your browser http://x.y.z.w:5001/ or http://x.y.z.w:5001/index or http://x.y.z.w:5001/index.html
API
initialize(urls)
urls:json file
initialize module (see example)
create(port)
port:number
start http server on specified port
setDebug(bool)
bool:bool
enable/disable console log