mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
added createInterface & localOrigin set
This commit is contained in:
parent
ce332cd8ef
commit
51ef45613c
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@corenode/cloudlink-addon",
|
||||
"version": "0.5.6",
|
||||
"version": "0.5.11",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"publishConfig": {
|
||||
@ -14,6 +14,6 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@ragestudio/cloudlink": "^0.5.6"
|
||||
"@ragestudio/cloudlink": "^0.5.11"
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ const cloudlink = require("../dist")
|
||||
const random = require("corenode/dist/libs/random")
|
||||
|
||||
// create server
|
||||
new cloudlink.Server({
|
||||
const server = new cloudlink.Server({
|
||||
autoInit: true,
|
||||
id: runtime.args.id ?? random.generateName()
|
||||
})
|
||||
})
|
||||
|
||||
// connect
|
||||
const client = cloudlink.Client.createInterface(server.localOrigin)
|
@ -1,37 +1,48 @@
|
||||
const axios = require("axios")
|
||||
const wsClient = require('websocket').client
|
||||
|
||||
const defaultRelicOrigin = global.DEFAULT_RELIC_ORIGIN
|
||||
let sockets = {}
|
||||
const RELIC_ORIGIN = global.RELIC_ORIGIN
|
||||
|
||||
function registerNewBridge() {
|
||||
|
||||
}
|
||||
|
||||
function resolveOrigin(origin) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
function connectToOrigin(origin) {
|
||||
if (typeof origin === "undefined") {
|
||||
origin = defaultRelicOrigin
|
||||
}
|
||||
return new DefaultBridge({
|
||||
origin: origin
|
||||
})
|
||||
}
|
||||
|
||||
class DefaultBridge {
|
||||
class Bridge {
|
||||
constructor(params) {
|
||||
this.params = params
|
||||
|
||||
this.origin = this.params.origin ?? "https://relic.ragestudio.net"
|
||||
|
||||
this.origin = this.params.origin
|
||||
this.headers = { ...this.params.headers }
|
||||
this.instance = axios.create({
|
||||
baseURL: this.origin,
|
||||
headers: this.headers
|
||||
})
|
||||
|
||||
this.map = null
|
||||
}
|
||||
|
||||
async connect() {
|
||||
//get map
|
||||
const req = await this.instance.get("/map")
|
||||
this.map = req.data
|
||||
}
|
||||
}
|
||||
|
||||
function createInterface(address) {
|
||||
|
||||
const bridge = new Bridge({
|
||||
origin: address
|
||||
})
|
||||
|
||||
bridge.connect()
|
||||
.then(() => {
|
||||
console.log(bridge.map)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
defaultRelicOrigin,
|
||||
registerNewBridge,
|
||||
Bridge,
|
||||
resolveOrigin,
|
||||
connectToOrigin
|
||||
createInterface,
|
||||
}
|
@ -3,7 +3,7 @@ const path = require('path')
|
||||
//* set globals
|
||||
global.runtime = runtime
|
||||
global.IS_DEV = runtime.helpers.isDevMode()
|
||||
global.DEFAULT_RELIC_ORIGIN = require('./relicOrigin.json')
|
||||
global.RELIC_ORIGIN = require('./relicOrigin.json')
|
||||
global.SERVER_VERSION = runtime.helpers.getVersion()
|
||||
global.SERVER_MANIFEST = "server.manifest"
|
||||
global.SERVER_MANIFEST_PATH = path.resolve(process.cwd(), SERVER_MANIFEST)
|
||||
|
@ -1,5 +1,18 @@
|
||||
const fs = require("fs")
|
||||
const express = require("express")
|
||||
function getIPAddress() {
|
||||
var interfaces = require('os').networkInterfaces();
|
||||
for (var devName in interfaces) {
|
||||
var iface = interfaces[devName];
|
||||
|
||||
for (var i = 0; i < iface.length; i++) {
|
||||
var alias = iface[i];
|
||||
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal)
|
||||
return alias.address;
|
||||
}
|
||||
}
|
||||
return '0.0.0.0';
|
||||
}
|
||||
|
||||
const { objectToArrayMap } = require("@corenode/utils")
|
||||
const tokenizer = require("corenode/dist/libs/tokenizer")
|
||||
@ -25,6 +38,7 @@ const defaultHeaders = {
|
||||
class Server {
|
||||
constructor(params, endpoints, middlewares) {
|
||||
this.params = params ?? {}
|
||||
this.port = this.params.port ?? 3010
|
||||
|
||||
// handle endpoints && middlewares
|
||||
const localEndpoints = getLocalEndpoints()
|
||||
@ -49,7 +63,7 @@ class Server {
|
||||
|
||||
//* set server basics
|
||||
this.httpServer = require("express")()
|
||||
|
||||
|
||||
//* set id's
|
||||
this.id = this.params.id ?? runtime.helpers.getRootPackage().name
|
||||
this.usid = tokenizer.generateUSID()
|
||||
@ -59,9 +73,9 @@ class Server {
|
||||
this._everyRequest = null
|
||||
this._onRequest = {}
|
||||
|
||||
if (typeof this.params.port === "undefined") {
|
||||
this.params.port = 3010
|
||||
}
|
||||
|
||||
this.localOrigin = `http://${getIPAddress()}:${this.port}`
|
||||
this.nethubOrigin = ""
|
||||
|
||||
if (this.params.autoInit) {
|
||||
this.init()
|
||||
@ -236,13 +250,13 @@ class Server {
|
||||
})
|
||||
})
|
||||
|
||||
this.httpServer.listen(this.params.port, () => {
|
||||
this.httpServer.listen(this.port, () => {
|
||||
//? register to nethub
|
||||
if (this.params.onlineNethub) {
|
||||
nethub.registerOrigin({ entry: "/", oskid: this.oskid, id: this.id })
|
||||
}
|
||||
|
||||
console.log(`✅ Ready on port ${this.params.port}!`)
|
||||
console.log(`✅ Ready on port ${this.port}!`)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user