mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-23 06:00:21 +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 { DevelopmentModule } = require("./src/modules/development/DevelopmentModule.js");
|
||||
const { HostOSModule } = require("./src/modules/hostos/HostOSModule.js");
|
||||
const { InternetModule } = require("./src/modules/internet/InternetModule.js");
|
||||
|
||||
module.exports = {
|
||||
helloworld: () => {
|
||||
@ -68,6 +69,7 @@ module.exports = {
|
||||
TestDriversModule,
|
||||
PuterAIModule,
|
||||
BroadcastModule,
|
||||
InternetModule,
|
||||
|
||||
// Development modules
|
||||
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',
|
||||
});
|
||||
res.json({ token });
|
||||
res.json({
|
||||
token,
|
||||
server: this.config.server,
|
||||
});
|
||||
}
|
||||
}).attach(r_wisp);
|
||||
|
||||
|
@ -321,15 +321,15 @@ window.puter = (function() {
|
||||
this.p_can_request_rao_.resolve();
|
||||
})();
|
||||
(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',
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.authToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({}),
|
||||
})).json())["token"];
|
||||
wispInfo.handler = new PWispHandler(wispInfo.server, wispToken);
|
||||
})).json());
|
||||
wispInfo.handler = new PWispHandler(wispServer, wispToken);
|
||||
this.net = {
|
||||
Socket: PSocket,
|
||||
tls: {
|
||||
|
@ -87,6 +87,7 @@ const main = async () => {
|
||||
BroadcastModule,
|
||||
TestDriversModule,
|
||||
PuterAIModule,
|
||||
InternetModule,
|
||||
DevelopmentModule
|
||||
} = (await import('@heyputer/backend')).default;
|
||||
|
||||
@ -101,6 +102,7 @@ const main = async () => {
|
||||
k.add_module(new SelfHostedModule());
|
||||
k.add_module(new BroadcastModule());
|
||||
k.add_module(new TestDriversModule());
|
||||
k.add_module(new InternetModule());
|
||||
// k.add_module(new PuterAIModule());
|
||||
if ( process.env.UNSAFE_PUTER_DEV ) {
|
||||
k.add_module(new DevelopmentModule());
|
||||
|
Loading…
Reference in New Issue
Block a user