mellon-server
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -14,2 +14,9 @@ #!/usr/bin/env node | ||
//options['registry'] = [ | ||
// { path: 'inbox/.*' , do: function(req,res) { | ||
// res.writeHead(200); | ||
// res.end('ok'); | ||
// }} | ||
//]; | ||
start_server(options); |
20
index.js
@@ -7,3 +7,3 @@ const http = require('http'); | ||
let public_dir = './public'; | ||
let registry = {} ; | ||
let registry = [] ; | ||
@@ -25,4 +25,6 @@ const log4js = require('log4js'); | ||
try { | ||
if (registry[pathItem]) { | ||
registry[pathItem](req,res); | ||
const reg = registryEntry(pathItem); | ||
if (reg) { | ||
reg(req,res); | ||
logger.info(`${req.method} ${req.url} [${res.statusCode}] 0`); | ||
@@ -62,2 +64,14 @@ return; | ||
function registryEntry(pathItem) { | ||
for (let i = 0 ; i < registry.length ; i++) { | ||
let regex = new RegExp('^' + registry[i]['path']); | ||
if (regex.test(pathItem)) { | ||
return registry[i]['do']; | ||
} | ||
} | ||
return null; | ||
} | ||
function doFile(path,req,res) { | ||
@@ -64,0 +78,0 @@ const content = fs.readFileSync(path, { encoding: 'utf-8'}); |
{ | ||
"name": "mellon-server", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A small hackable HTTP server", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,3 +8,3 @@ # mellon-server | ||
``` | ||
npm install pico-server | ||
npm install mellon-server | ||
``` | ||
@@ -15,3 +15,3 @@ | ||
``` | ||
const { start_server } = require('../index.js'); | ||
const { start_server } = require('mellon-server'); | ||
@@ -22,5 +22,5 @@ start_server({ | ||
public: './public' | ||
registry: { | ||
'demo': doDemo | ||
} | ||
registry: [ | ||
{ path: 'demo' , do: doDemo } | ||
] | ||
}); | ||
@@ -27,0 +27,0 @@ |
5298
14
126