Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
rjweb-server
Advanced tools
Easy Way to create a web Server in node.js
npm i rjweb-server
Initialize Server
/* ************ *
* EXPERIMENTAL *
* ************ */
// You shouldnt use the current
// State for Production Use
const webserver = require('rjweb-server')
const routes = new webserver.RouteList()
// ctr.query.get... is ?name=
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?`)
})
// ctr.param.get... is :name, example /hello/0x4096
routes.set(webserver.types.get, '/hello/:name', async(ctr) => {
ctr.print(`Hello, ${ctr.param.get("name")}! How are you doing?`)
})
// ctr.param.get... is :name, example /hello/0x4096
routes.set(webserver.types.post, '/post', async(ctr) => {
ctr.print(`Hello, ${ctr.reqBody}! How are you doing?`)
})
webserver.start({
bind: '0.0.0.0',
cors: false,
port: 5000,
urls: routes
}).then((res) => {
console.log(`webserver started on port ${res.port}`)
})
Serve Static Files
/* ************ *
* EXPERIMENTAL *
* ************ */
// You shouldnt use the current
// State for Production Use
const webserver = require('rjweb-server')
const routes = new webserver.RouteList()
routes.static('/', './html') // The html folder is in the root directory
webserver.start({
bind: '0.0.0.0',
cors: false,
port: 5000,
urls: routes
}).then((res) => {
console.log(`webserver started on port ${res.port}`)
})
Custom 404 / 500 Page
/* ************ *
* EXPERIMENTAL *
* ************ */
// You shouldnt use the current
// State for Production Use
webserver.start({
bind: '0.0.0.0',
cors: false,
port: port,
urls: routes,
pages: {
notFound: async(ctr) {
ctr.status(404)
ctr.print(`page "${ctr.reqUrl.pathname}" not found`)
}, reqError: async(ctr) => {
ctr.status(500)
ctr.print(`ERROR!!! ${ctr.error.message}`)
console.log(ctr.error)
}
}
}).then((res) => {
console.log(`webserver started on port ${res.port}`)
})
Custom Function on every request
/* ************ *
* EXPERIMENTAL *
* ************ */
// You shouldnt use the current
// State for Production Use
webserver.start({
bind: '0.0.0.0',
cors: false,
port: port,
urls: routes,
events: {
request: async(ctr) => {
console.log(`request made to ${decodeURI(ctr.reqUrl.pathname)}`) // DO NOT write any data or end the request
}
}
}).then((res) => {
console.log(`webserver started on port ${res.port}`)
})
Load Functions from Directory
/* ************ *
* EXPERIMENTAL *
* ************ */
// You shouldnt use the current
// State for Production Use
const webserver = require('rjweb-server')
const routes = new webserver.RouteList()
routes.load('./functions') // The functions folder is in the root directory
webserver.start({
bind: '0.0.0.0',
cors: false,
port: 5000,
urls: routes
}).then((res) => {
console.log(`webserver started on port ${res.port}`)
})
Making a function File
const webserver = require('rjweb-server')
module.exports = {
type: webserver.types.get,
path: '/say/:word',
async code(ctr) {
ctr.print(ctr.param.get('word'))
}
}
👤 0x4096
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
Copyright © 2022 0x4096.
This project is ISC licensed.
FAQs
Easy and Robust Way to create a Web Server with many easy-to-use Features in Node.js
The npm package rjweb-server receives a total of 481 weekly downloads. As such, rjweb-server popularity was classified as not popular.
We found that rjweb-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.