0.2.2 • Published 10 years ago

http-dispatcher v0.2.2

Weekly downloads
2
License
GPL
Repository
github
Last release
10 years ago

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

0.2.2

10 years ago

0.2.1

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago