From fd41ae217c7a9f7229326f62a829471580a744bd Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Sun, 7 Jul 2024 20:45:02 -0400 Subject: [PATCH] feat: support canonical puter.js url in dev --- src/backend/src/SelfHostedModule.js | 7 +++++++ .../src/services/ServeSingeFileService.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/backend/src/services/ServeSingeFileService.js diff --git a/src/backend/src/SelfHostedModule.js b/src/backend/src/SelfHostedModule.js index 9b1bcf4a..11455583 100644 --- a/src/backend/src/SelfHostedModule.js +++ b/src/backend/src/SelfHostedModule.js @@ -76,6 +76,13 @@ class SelfHostedModule extends AdvancedBase { }, ], }); + + const { ServeSingleFileService } = require('./services/ServeSingeFileService'); + services.registerService('__serve-puterjs-new', ServeSingleFileService, { + path: path_.resolve(__dirname, + '../../../src/puter-js/dist/puter.dev.js'), + route: '/puter.js/v2', + }); } } diff --git a/src/backend/src/services/ServeSingeFileService.js b/src/backend/src/services/ServeSingeFileService.js new file mode 100644 index 00000000..e3d831e5 --- /dev/null +++ b/src/backend/src/services/ServeSingeFileService.js @@ -0,0 +1,19 @@ +const BaseService = require("./BaseService"); + +class ServeSingleFileService extends BaseService { + async _init (args) { + this.route = args.route; + this.path = args.path; + } + async ['__on_install.routes'] () { + const { app } = this.services.get('web-server'); + + app.get(this.route, (req, res) => { + return res.sendFile(this.path); + }); + } +} + +module.exports = { + ServeSingleFileService, +};