Socket
Socket
Sign inDemoInstall

rjweb-server

Package Overview
Dependencies
Maintainers
1
Versions
373
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rjweb-server - npm Package Compare versions

Comparing version 0.3.0 to 0.3.5

utils/getAllFiles.js

58

index.js

@@ -36,3 +36,3 @@ const { RouteList } = require('./utils/RouteList')

let params = new Map()
let exists = false
let exists, isStatic = false
const actualUrl = reqUrl.pathname.split('/')

@@ -43,5 +43,12 @@ if (actualUrl[actualUrl.length - 1] === '') actualUrl.pop()

executeUrl = reqUrl.pathname
isStatic = false
exists = true
break
}; if (elementName in urls && elementName === reqUrl.pathname && urls[elementName].type === 'STATIC') {
executeUrl = reqUrl.pathname
isStatic = true
exists = true
break
}

@@ -93,14 +100,2 @@

// Get POST Body
/*res.write('')
let reqBody = '';
res.on('data', (data) => {
reqBody += data.toString()
})
await new Promise((resolve) => {
res.once('end', resolve)
})*/
let ctr = {

@@ -141,3 +136,3 @@ // Properties

res.statusCode = 500
res.write('error errored')
res.write(e.message)
return res.end()

@@ -157,16 +152,21 @@ }); return res.end()

await urls[executeUrl].code(ctr).catch((e) => {
if ('reqError' in pages) {
ctr.error = e.message
options.pages.reqError(ctr).catch((e) => {
if (!isStatic) {
await urls[executeUrl].code(ctr).catch((e) => {
if ('reqError' in pages) {
ctr.error = e.message
options.pages.reqError(ctr).catch((e) => {
res.statusCode = 500
res.write(e.message)
res.end()
}); return res.end()
} else {
res.statusCode = 500
res.write('error errored')
res.write(e.message)
res.end()
}); return res.end()
} else {
res.statusCode = 500
res.write(e.message)
res.end()
}
}); return res.end()
}
}); return res.end()
} else {
res.write(urls[executeUrl].content)
return res.end()
}
} else {

@@ -180,3 +180,3 @@

res.statusCode = 500
res.write('error errored')
res.write(e.message)
res.end()

@@ -193,3 +193,5 @@ }); return res.end()

Object.keys(urls).forEach(function(url) {
pageDisplay = pageDisplay + `[-] [${urls[url].type}] ${url}\n`
const type = (urls[url].type === 'STATIC' ? 'GET' : urls[url].type)
pageDisplay = pageDisplay + `[-] [${type}] ${url}\n`
})

@@ -196,0 +198,0 @@

{
"name": "rjweb-server",
"version": "0.3.0",
"version": "0.3.5",
"description": "Easy Way to create a Web Server in Node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -59,2 +59,25 @@ <h1 align="center">Welcome to rjweb-server 👋</h1>

Serve Static Files
```js
/* ************ *
* 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

@@ -61,0 +84,0 @@ ```js

@@ -0,2 +1,6 @@

const { getAllFiles } = require('./getAllFiles.js')
const fs = require('node:fs')
const types = [
'STATIC',
'POST',

@@ -18,3 +22,16 @@ 'GET'

}
}; list() {
}; static(path, folder) {
const files = getAllFiles(folder)
for (const file of files) {
const fileName = file.replace(folder, '')
this.urls[path + fileName] = {
array: fileName.split('/'),
type: 'STATIC',
content: fs.readFileSync(file, 'utf8')
}
}
}
list() {
return this.urls

@@ -21,0 +38,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc