diff --git a/package.json b/package.json index 25f89af..f7eb011 100755 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/server/http/index.js b/src/server/http/index.js index 42b6b85..2262338 100755 --- a/src/server/http/index.js +++ b/src/server/http/index.js @@ -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') + + //? register to nethub + if (this.params.onlineNethub) { + nethub.registerOrigin({ entry: "/", oskid: this.oskid, id: this.id }) + } - 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 }) - } - - console.log(`✅ Ready on port ${this.port}!`) - }) + console.log(`✅ Ready on port ${this.port}!`) } }