diff --git a/.DS_Store b/.DS_Store index 5b47d9d..a8cff0e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.corenode.json b/.corenode.json index 304d7b2..13bf1a8 100755 --- a/.corenode.json +++ b/.corenode.json @@ -1,4 +1,4 @@ { - "version": "0.10.14", + "version": "0.11.0", "fixedMainScript": "./client/index.js" } diff --git a/package.json b/package.json index 4fd5bad..8c878f6 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linebridge", - "version": "0.10.14", + "version": "0.11.0", "description": "A simple, fast, and powerful REST API interface library", "author": "RageStudio", "main": "./dist/client/index.js", @@ -19,15 +19,14 @@ "license": "MIT", "dependencies": { "@corenode/utils": "0.28.26", - "@nanoexpress/middleware-body-parser": "1.2.2", - "axios": "0.26.0", + "axios": "0.27.2", "cors": "2.8.5", + "hyper-express": "^6.1.1", "md5": "2.3.0", - "nanoexpress": "5.1.2", - "nanoid": "3.3.1", - "socket.io-client": "4.4.1", - "socket.io": "4.4.1", "morgan": "1.10.0", + "nanoid": "3.3.4", + "socket.io": "4.5.0", + "socket.io-client": "4.5.0", "uuid": "8.3.2" }, "devDependencies": { diff --git a/src/bin/server.js b/src/bin/server.js index 976b85f..b4a76ea 100755 --- a/src/bin/server.js +++ b/src/bin/server.js @@ -4,7 +4,9 @@ const corenode = require("corenode") corenode.runInNewRuntime(() => { const server = require("../server/index.js") - new server({ + const instance = new server({ id: process.env.serverID, }) + + instance.initialize() }) \ No newline at end of file diff --git a/src/server/index.js b/src/server/index.js index 9147a83..136d2d0 100755 --- a/src/server/index.js +++ b/src/server/index.js @@ -2,7 +2,7 @@ const path = require("path") const fs = require("fs") const net = require("corenode/net") -const http = require("nanoexpress") +const HyperExpress = require("hyper-express") const io = require("socket.io") const packageJSON = require(path.resolve(module.path, "../../package.json")) @@ -26,7 +26,6 @@ global.DEFAULT_HEADERS = { } const defaultMiddlewares = [ - require("@nanoexpress/middleware-body-parser/cjs")(), require('cors')({ "origin": "*", "methods": DEFAULT_HEADERS["Access-Control-Allow-Methods"], @@ -40,7 +39,7 @@ const FixedMethods = { } if (process.env.NODE_ENV !== "production") { - defaultMiddlewares.push(require('morgan')("dev")) + defaultMiddlewares.push(require("morgan")("dev")) } class Server { @@ -51,7 +50,7 @@ class Server { this.headers = { ...DEFAULT_HEADERS, ...this.params.headers } this.endpointsMap = {} - this.WSListenPort = this.params.wsPort ?? 3011 + this.WSListenPort = this.params.wsPort ?? 3020 this.HTTPlistenPort = this.params.port ?? 3010 // TODO: Handle HTTPS and WSS @@ -59,7 +58,7 @@ class Server { this.WSAddress = `ws://${LOCALHOST_ADDRESS}:${this.WSListenPort}` //* set server basics - this.httpInterface = global.httpInterface = http() + this.httpInterface = global.httpInterface = new HyperExpress.Server() this.wsInterface = global.wsInterface = { io: new io.Server(this.WSListenPort), map: {}, @@ -120,7 +119,14 @@ class Server { // initialize http server await this.httpInterface.listen(this.HTTPlistenPort, this.params.listen ?? "0.0.0.0") - console.log(`✅ Ready on port ${this.HTTPlistenPort}!`) + // output server info + console.log(`✅ Server is up and running!`) + this.consoleOutputServerInfo() + + // handle exit events + process.on("SIGTERM", this.cleanupProcess) + process.on("SIGINT", this.cleanupProcess) + process.on("exit", this.cleanupProcess) } handleWSClientConnection = async (socket) => { @@ -275,6 +281,25 @@ class Server { } }) } + + consoleOutputServerInfo = () => { + console.log(`🌐 Server info:`) + console.table({ + "ID": this.id, + "Version": LINEBRIDGE_SERVER_VERSION, + "HTTP address": this.HTTPAddress, + "WS address": this.WSAddress, + "WS port": this.WSListenPort, + "HTTP port": this.HTTPlistenPort, + }) + } + + cleanupProcess = () => { + console.log("🔴 Stopping server...") + + this.httpInterface.close() + this.wsInterface.io.close() + } } module.exports = Server \ No newline at end of file