Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/backend/src/modules/web/WebServerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const config = require('../../config.js');
var http = require('http');
const auth = require('../../middleware/auth.js');
const measure = require('../../middleware/measure.js');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');

const relative_require = require;

Expand Down Expand Up @@ -202,6 +204,13 @@ class WebServerService extends BaseService {

const url = config.origin;

const args = yargs(hideBin(process.argv)).argv;
if ( args['server'] ) {
(async () => {
(await import('./../../../../../tools/auth_gui.js')).default(args['puter-backend']);
})();
config.no_browser_launch = true;
}
// Open the browser to the URL of Puter
// (if we are in development mode only)
if ( config.env === 'dev' && !config.no_browser_launch ) {
Expand Down
19 changes: 19 additions & 0 deletions tools/auth_gui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import open from 'open';
import http from 'node:http';

export default function (guiOrigin = 'https://puter.com') {

return new Promise((resolve) => {
const requestListener = function (/**@type {IncomingMessage} */ req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<script>window.location.href="http://puter.localhost:4100/?api_origin=https://api.puter.com&auth_token=" + new URL(location.href).searchParams.get("token") </script>');

resolve(new URL(req.url, 'http://localhost/').searchParams.get('token'));
};
const server = http.createServer(requestListener);
server.listen(0, function () {
const url = `${guiOrigin}/?action=authme&redirectURL=${encodeURIComponent('http://localhost:') + this.address().port}`;
open(url);
});
});
};
Loading