Merge pull request #1 from ragestudio/replace-express

nanoexpress
This commit is contained in:
srgooglo 2021-10-18 09:12:07 +02:00 committed by GitHub
commit 8e6f223882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 18 deletions

View File

@ -19,16 +19,18 @@
],
"license": "MIT",
"dependencies": {
"socket.io": "^4.2.0",
"@corenode/helpers": "^0.28.18",
"@corenode/utils": "^0.28.18",
"corenode": "^0.28.18",
"axios": "^0.22.0",
"body-parser": "^1.19.0",
"corenode": "^0.28.18",
"cors": "^2.8.5",
"express": "^4.17.1",
"md5": "^2.3.0",
"morgan": "^1.10.0",
"nanoexpress": "^5.1.2",
"nanoid": "^3.1.28",
"socket.io": "^4.2.0",
"uuid": "^8.3.2",
"websocket": "^1.0.34"
},

View File

@ -1,5 +1,6 @@
const fs = require("fs")
const express = require("express")
const http = require("nanoexpress")
const bodyParser = require('body-parser')
const { nanoid } = require("nanoid")
const tokenizer = require("corenode/libs/tokenizer")
@ -47,8 +48,7 @@ class Server {
this.headers = { ...defaultHeaders, ...this.params.headers }
//* set server basics
this.httpServer = require("express")()
this.router = express.Router()
this.httpServer = http()
//* set id's
this.id = this.params.id ?? process.runtime?.helpers?.getRootPackage()?.name ?? "unavailable"
@ -178,13 +178,13 @@ class Server {
}
// append to router
this.router[controller.method](...routeModel)
this.httpServer[controller.method](...routeModel)
}
preInitialization() {
// set middlewares
this.httpServer.use(express.json())
this.httpServer.use(express.urlencoded({ extended: true }))
this.httpServer.use(bodyParser.json())
this.httpServer.use(bodyParser.urlencoded({ extended: true }))
if (Array.isArray(this.serverMiddlewares)) {
this.serverMiddlewares.forEach((middleware) => {
@ -251,7 +251,7 @@ class Server {
})
}
init() {
init = async () => {
// write lastStart
serverManifest.write({ lastStart: Date.now() })
@ -268,16 +268,14 @@ class Server {
})
}
this.httpServer.use('/', this.router)
await this.httpServer.listen(this.port, this.params.listen ?? '0.0.0.0')
this.httpServer.listen(this.port, this.params.listen ?? '0.0.0.0', () => {
//? register to nethub
if (this.params.onlineNethub) {
nethub.registerOrigin({ entry: "/", oskid: this.oskid, id: this.id })
}
//? register to nethub
if (this.params.onlineNethub) {
nethub.registerOrigin({ entry: "/", oskid: this.oskid, id: this.id })
}
console.log(`✅ Ready on port ${this.port}!`)
})
console.log(`✅ Ready on port ${this.port}!`)
}
}