http-dispatcher

0.2.2 • Public • Published

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

<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<b>Hello world</b>
</body>
</html>

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

Contributors

Package Sidebar

Install

npm i http-dispatcher

Weekly Downloads

1

Version

0.2.2

License

GPL

Last publish

Collaborators

  • hormander