rjweb-server
Advanced tools
Comparing version 0.2.1 to 0.2.2
19
index.js
@@ -1,2 +0,1 @@ | ||
const sleep = (milliseconds) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds) | ||
const { RouteList } = require('./utils/RouteList') | ||
@@ -112,2 +111,6 @@ const http = require('node:http') | ||
// Raw Values | ||
rawReq: req, | ||
rawRes: res, | ||
// Functions | ||
@@ -129,3 +132,3 @@ print(msg) { | ||
await urls[executeUrl].code(ctr).catch((e) => { | ||
if (!options.hasOwnProperty('reqError')) { | ||
if (!options.pages.reqError) { | ||
res.statusCode = 500 | ||
@@ -136,3 +139,3 @@ res.write(e.message) | ||
ctr.error = e.message | ||
options.reqError(ctr).catch((e) => { | ||
options.pages.reqError(ctr).catch((e) => { | ||
res.statusCode = 500 | ||
@@ -146,6 +149,6 @@ res.write('error errored') | ||
if (!options.hasOwnProperty('notFound')) { | ||
if (!options.pages.notFound) { | ||
let pageDisplay = '' | ||
Object.keys(urls).forEach(function(url) { | ||
pageDisplay = pageDisplay + `[-] [${urls[url].type}] ${url}` | ||
pageDisplay = pageDisplay + `[-] [${urls[url].type}] ${url}\n` | ||
}) | ||
@@ -158,4 +161,4 @@ | ||
} else { | ||
await options.notFound(ctr).catch((e) => { | ||
if (!options.hasOwnProperty('reqError')) { | ||
await options.pages.notFound(ctr).catch((e) => { | ||
if (!options.pages.reqError) { | ||
res.statusCode = 500 | ||
@@ -166,3 +169,3 @@ res.write(e.message) | ||
ctr.error = e.message | ||
options.reqError(ctr).catch((e) => { | ||
options.pages.reqError(ctr).catch((e) => { | ||
res.statusCode = 500 | ||
@@ -169,0 +172,0 @@ res.write('error errored') |
{ | ||
"name": "rjweb-server", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Easy Way to create a Web Server in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -39,2 +39,4 @@ <h1 align="center">Welcome to rjweb-server 👋</h1> | ||
routes.set(webserver.types.get, '/hello', async(ctr) => { | ||
if (!ctr.query.has("name")) return ctr.print('please supply the name query!!') | ||
ctr.print(`Hello, ${ctr.query.get("name")}! How are you doing?`) | ||
@@ -71,8 +73,10 @@ }) | ||
urls: routes, | ||
notFound: async(ctr) { | ||
ctr.status(404) | ||
ctr.print(`page "${ctr.requestPath.pathname}" not found`) | ||
}, reqError: async(ctr) => { | ||
ctr.status(500) | ||
ctr.print(`ERROR!!! ${ctr.error}`) | ||
pages: { | ||
notFound: async(ctr) { | ||
ctr.status(404) | ||
ctr.print(`page "${ctr.requestPath.pathname}" not found`) | ||
}, reqError: async(ctr) => { | ||
ctr.status(500) | ||
ctr.print(`ERROR!!! ${ctr.error}`) | ||
} | ||
} | ||
@@ -79,0 +83,0 @@ }).then((res) => { |
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
9694
172
102