rjweb-server
Advanced tools
Comparing version 0.1.4 to 0.2.0
35
index.js
@@ -100,3 +100,3 @@ const sleep = (milliseconds) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds) | ||
const ctr = { | ||
let ctr = { | ||
// Properties | ||
@@ -125,2 +125,3 @@ header: headers, | ||
res.setHeader('X-Powered-By', 'rjweb-server') | ||
if (exists) { | ||
@@ -130,8 +131,18 @@ res.writeHead(200, corsHeaders) | ||
await urls[executeUrl].code(ctr).catch((e) => { | ||
res.write(e.message) | ||
res.end() | ||
if (!options.hasOwnProperty('reqError')) { | ||
res.statusCode = 500 | ||
res.write(e.message) | ||
res.end() | ||
} else { | ||
ctr.error = e.message | ||
options.reqError(ctr).catch((e) => { | ||
res.statusCode = 500 | ||
res.write('error errored') | ||
res.end() | ||
}); return res.end() | ||
} | ||
}); return res.end() | ||
} else { | ||
if (!options.hasOwnProperty('notfound')) { | ||
if (!options.hasOwnProperty('notFound')) { | ||
let pageDisplay = '' | ||
@@ -147,5 +158,15 @@ Object.keys(urls).forEach(function(url) { | ||
} else { | ||
await options.notfound(ctr).catch((e) => { | ||
res.write(e.message) | ||
res.end() | ||
await options.notFound(ctr).catch((e) => { | ||
if (!options.hasOwnProperty('reqError')) { | ||
res.statusCode = 500 | ||
res.write(e.message) | ||
res.end() | ||
} else { | ||
ctr.error = e.message | ||
options.reqError(ctr).catch((e) => { | ||
res.statusCode = 500 | ||
res.write('error errored') | ||
res.end() | ||
}); return res.end() | ||
} | ||
}); return res.end() | ||
@@ -152,0 +173,0 @@ } |
{ | ||
"name": "rjweb-server", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "Easy Way to create a Web Server in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -57,3 +57,3 @@ <h1 align="center">Welcome to rjweb-server 👋</h1> | ||
Custom 404 Page | ||
Custom 404 / 500 Page | ||
```js | ||
@@ -71,5 +71,8 @@ /* ************ * | ||
urls: routes, | ||
notfound: async(ctr) { | ||
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}`) | ||
} | ||
@@ -76,0 +79,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
9673
171
98