mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
Merge pull request #2 from ragestudio/hyper-express-update
Hyper express update
This commit is contained in:
commit
f1d83f663d
@ -1,4 +1,4 @@
|
||||
{
|
||||
"version": "0.10.14",
|
||||
"version": "0.11.0",
|
||||
"fixedMainScript": "./client/index.js"
|
||||
}
|
||||
|
13
package.json
13
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": {
|
||||
|
@ -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()
|
||||
})
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user