mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-23 14:20:22 +08:00
dev: add wisp relay service
This commit is contained in:
parent
4c72e9d285
commit
591c6c0fd3
@ -35,6 +35,7 @@ const { PerfMonModule } = require("./src/modules/perfmon/PerfMonModule.js");
|
|||||||
const { AppsModule } = require("./src/modules/apps/AppsModule.js");
|
const { AppsModule } = require("./src/modules/apps/AppsModule.js");
|
||||||
const { DevelopmentModule } = require("./src/modules/development/DevelopmentModule.js");
|
const { DevelopmentModule } = require("./src/modules/development/DevelopmentModule.js");
|
||||||
const { HostOSModule } = require("./src/modules/hostos/HostOSModule.js");
|
const { HostOSModule } = require("./src/modules/hostos/HostOSModule.js");
|
||||||
|
const { InternetModule } = require("./src/modules/internet/InternetModule.js");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
helloworld: () => {
|
helloworld: () => {
|
||||||
@ -68,6 +69,7 @@ module.exports = {
|
|||||||
TestDriversModule,
|
TestDriversModule,
|
||||||
PuterAIModule,
|
PuterAIModule,
|
||||||
BroadcastModule,
|
BroadcastModule,
|
||||||
|
InternetModule,
|
||||||
|
|
||||||
// Development modules
|
// Development modules
|
||||||
PerfMonModule,
|
PerfMonModule,
|
||||||
|
18
src/backend/src/modules/internet/InternetModule.js
Normal file
18
src/backend/src/modules/internet/InternetModule.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const { AdvancedBase } = require("@heyputer/putility");
|
||||||
|
const config = require("../../config.js");
|
||||||
|
|
||||||
|
class InternetModule extends AdvancedBase {
|
||||||
|
async install (context) {
|
||||||
|
const services = context.get('services');
|
||||||
|
|
||||||
|
if ( !! config?.services?.['wisp-relay'] ) {
|
||||||
|
const WispRelayService = require('./WispRelayService.js');
|
||||||
|
services.registerService('wisp-relay', WispRelayService);
|
||||||
|
} else {
|
||||||
|
this.log.noticeme('WISP Relay is disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { InternetModule };
|
18
src/backend/src/modules/internet/WispRelayService.js
Normal file
18
src/backend/src/modules/internet/WispRelayService.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const BaseService = require("../../services/BaseService");
|
||||||
|
|
||||||
|
class WispRelayService extends BaseService {
|
||||||
|
_init () {
|
||||||
|
const path_ = require('path');
|
||||||
|
const svc_process = this.services.get('process');
|
||||||
|
svc_process.start({
|
||||||
|
command: this.config.node_path,
|
||||||
|
fullpath: this.config.wisp_relay_path,
|
||||||
|
args: ['index.js'],
|
||||||
|
env: {
|
||||||
|
PORT: this.config.wisp_relay_port,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = WispRelayService;
|
@ -45,7 +45,10 @@ class WispService extends BaseService {
|
|||||||
}, {
|
}, {
|
||||||
expiresIn: '1d',
|
expiresIn: '1d',
|
||||||
});
|
});
|
||||||
res.json({ token });
|
res.json({
|
||||||
|
token,
|
||||||
|
server: this.config.server,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}).attach(r_wisp);
|
}).attach(r_wisp);
|
||||||
|
|
||||||
|
@ -321,15 +321,15 @@ window.puter = (function() {
|
|||||||
this.p_can_request_rao_.resolve();
|
this.p_can_request_rao_.resolve();
|
||||||
})();
|
})();
|
||||||
(async () => {
|
(async () => {
|
||||||
const wispToken = (await (await fetch(this.APIOrigin + '/wisp/relay-token/create', {
|
const { token: wispToken, server: wispServer } = (await (await fetch(this.APIOrigin + '/wisp/relay-token/create', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${this.authToken}`,
|
Authorization: `Bearer ${this.authToken}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
})).json())["token"];
|
})).json());
|
||||||
wispInfo.handler = new PWispHandler(wispInfo.server, wispToken);
|
wispInfo.handler = new PWispHandler(wispServer, wispToken);
|
||||||
this.net = {
|
this.net = {
|
||||||
Socket: PSocket,
|
Socket: PSocket,
|
||||||
tls: {
|
tls: {
|
||||||
|
@ -87,6 +87,7 @@ const main = async () => {
|
|||||||
BroadcastModule,
|
BroadcastModule,
|
||||||
TestDriversModule,
|
TestDriversModule,
|
||||||
PuterAIModule,
|
PuterAIModule,
|
||||||
|
InternetModule,
|
||||||
DevelopmentModule
|
DevelopmentModule
|
||||||
} = (await import('@heyputer/backend')).default;
|
} = (await import('@heyputer/backend')).default;
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ const main = async () => {
|
|||||||
k.add_module(new SelfHostedModule());
|
k.add_module(new SelfHostedModule());
|
||||||
k.add_module(new BroadcastModule());
|
k.add_module(new BroadcastModule());
|
||||||
k.add_module(new TestDriversModule());
|
k.add_module(new TestDriversModule());
|
||||||
|
k.add_module(new InternetModule());
|
||||||
// k.add_module(new PuterAIModule());
|
// k.add_module(new PuterAIModule());
|
||||||
if ( process.env.UNSAFE_PUTER_DEV ) {
|
if ( process.env.UNSAFE_PUTER_DEV ) {
|
||||||
k.add_module(new DevelopmentModule());
|
k.add_module(new DevelopmentModule());
|
||||||
|
Loading…
Reference in New Issue
Block a user