![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
rjweb-server
Advanced tools
Readme
Easy and Lightweight 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!!')
return 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) => {
return 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) => {
return ctr.print(`Hello, ${ctr.reqBody}! How are you doing?`)
})
routes.set(webserver.types.get, '/profile/:user', async(ctr) => {
ctr.setHeader('Content-Type', 'image/png')
return ctr.printFile(`../images/profile/${ctr.param.get('user')}.png`)
})
webserver.start({
bind: '0.0.0.0', // The IP thats bound to
body: 20, // The Max POST Body in MB
cors: false, // If Cors Headers will be added
port: 5000, // The Port which the Server runs on
urls: routes, // The Routes Object
proxy: true // If enabled, alternate IPs will be shown
}).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', {
preload: false, // If enabled will load every static files content into Memory
remHTML: true // If enabled will remove the html ending from files when serving
}) // The html folder is in the root directory
webserver.start({
bind: '0.0.0.0',
cors: false,
port: 5000,
urls: routes,
proxy: true
}).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,
proxy: true,
pages: {
notFound: async(ctr) {
ctr.status(404)
return ctr.print(`page "${ctr.reqUrl.pathname}" not found`)
}, reqError: async(ctr) => {
ctr.status(500)
ctr.print(`ERROR!!! ${ctr.error.message}`)
return 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,
proxy: true,
events: {
request: async(ctr) => {
return console.log(`request made to ${decodeURI(ctr.reqUrl.pathname)} by ${ctr.hostIp}`) // 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,
proxy: true,
}).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) {
const word = ctr.param.get('word')
return ctr.print(`I will say it!!!\n${word}`)
}
}
https://replit.com/@RobertJansen/aous
š¤ 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 NodeJS
The npm package rjweb-server receives a total of 25 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 1 open source maintainer 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.