mellon-server
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -1,6 +0,6 @@ | ||
function handle(req,res) { | ||
function handle(req,res,options) { | ||
res.writeHead(200); | ||
res.end('Yeah! :)'); | ||
res.end(`Yeah! :) ${JSON.stringify(options)}`); | ||
} | ||
module.exports = { handle }; |
13
index.js
@@ -27,6 +27,6 @@ const http = require('http'); | ||
try { | ||
const reg = registryEntry(pathItem); | ||
const entry = registryEntry(pathItem); | ||
if (reg) { | ||
reg(req,res); | ||
if (entry) { | ||
entry['function'](req,res,entry['options']); | ||
logger.info(`${address} - ${req.method} ${req.url} [${res.statusCode}] 0`); | ||
@@ -72,6 +72,7 @@ return; | ||
if (regex.test(pathItem)) { | ||
const entry = registry[i]['do']; | ||
const entry = registry[i]['do']; | ||
const options = registry[i]['with']; | ||
if (typeof entry === 'function') { | ||
return entry; | ||
return { function: entry , options: options }; | ||
} | ||
@@ -83,3 +84,3 @@ else { | ||
registry[i]['do'] = func; | ||
return func; | ||
return { function: func , options: options }; | ||
} | ||
@@ -86,0 +87,0 @@ } |
{ | ||
"name": "mellon-server", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "A small hackable HTTP server", | ||
@@ -11,3 +11,4 @@ "main": "index.js", | ||
"scripts": { | ||
"server": "npx mellon-server" | ||
"server": "npx mellon-server", | ||
"server-registry": "npx mellon-server --registry registry-example.json" | ||
}, | ||
@@ -14,0 +15,0 @@ "dependencies": { |
@@ -29,7 +29,7 @@ # mellon-server | ||
{ path: 'demo' , do: doDemo }, | ||
{ path: 'test/.*', do: './hander/demo.js'} | ||
{ path: 'test/.*', do: './hander/demo.js', with: { myOption: 123 }} | ||
] | ||
}); | ||
function doDemo(req,res) { | ||
function doDemo(req,res,opts) { | ||
res.writeHead(200); | ||
@@ -36,0 +36,0 @@ res.end('Hello World!'); |
[ | ||
{ "path": "demo/.*" , "do": "./handler/demo.js" } | ||
{ "path": "demo/.*" , "do": "./handler/demo.js" , "with": { "test": 123 }} | ||
] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7175
162