From a8fc4669e84445a3300151c8fb54994ea500195e Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Thu, 2 Jan 2025 16:23:02 -0500 Subject: [PATCH] dev: fix default origins in puter.js --- .../src/modules/selfhosted/SelfHostedModule.js | 4 ++++ src/puter-js/package.json | 4 ++-- src/puter-js/src/index.js | 4 ++-- src/puter-js/webpack.config.js | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/puter-js/webpack.config.js diff --git a/src/backend/src/modules/selfhosted/SelfHostedModule.js b/src/backend/src/modules/selfhosted/SelfHostedModule.js index f49ed414..2dc0587c 100644 --- a/src/backend/src/modules/selfhosted/SelfHostedModule.js +++ b/src/backend/src/modules/selfhosted/SelfHostedModule.js @@ -50,6 +50,10 @@ class SelfHostedModule extends AdvancedBase { directory: 'src/puter-js', command: 'npm', args: ['run', 'start-webpack'], + env: { + PUTER_ORIGIN: ({ global_config: config }) => config.origin, + PUTER_API_ORIGIN: ({ global_config: config }) => config.api_base_url, + }, }, { name: 'gui:webpack-watch', diff --git a/src/puter-js/package.json b/src/puter-js/package.json index 2e63edab..0c1e02f6 100644 --- a/src/puter-js/package.json +++ b/src/puter-js/package.json @@ -5,9 +5,9 @@ "main": "index.js", "scripts": { "start-server": "npx http-server --cors -c-1", - "start-webpack": "webpack ./src/index.js --output-filename puter.js && webpack ./src/index.js --output-filename puter.dev.js --watch --devtool source-map", + "start-webpack": "webpack && webpack --output-filename puter.dev.js --watch --devtool source-map", "start": "concurrently \"npm run start-server\" \"npm run start-webpack\"", - "build": "webpack ./src/index.js --output-filename puter.js && { echo \"// Copyright 2024 Puter Technologies Inc. All rights reserved.\"; echo \"// Generated on $(date '+%Y-%m-%d %H:%M')\n\"; cat ./dist/puter.js; } > temp && mv temp ./dist/puter.js" + "build": "webpack && { echo \"// Copyright 2024 Puter Technologies Inc. All rights reserved.\"; echo \"// Generated on $(date '+%Y-%m-%d %H:%M')\n\"; cat ./dist/puter.js; } > temp && mv temp ./dist/puter.js" }, "keywords": [], "author": "", diff --git a/src/puter-js/src/index.js b/src/puter-js/src/index.js index 5ff07bef..a902aea7 100644 --- a/src/puter-js/src/index.js +++ b/src/puter-js/src/index.js @@ -30,8 +30,8 @@ window.puter = (function() { // 'web' means the SDK is running in a 3rd-party website. env; - defaultAPIOrigin = 'https://api.puter.com'; - defaultGUIOrigin = 'https://puter.com'; + defaultAPIOrigin = globalThis.PUTER_API_ORIGIN ?? 'https://api.puter.com'; + defaultGUIOrigin = globalThis.PUTER_ORIGIN ?? 'https://puter.com'; // An optional callback when the user is authenticated. This can be set by the app using the SDK. onAuth; diff --git a/src/puter-js/webpack.config.js b/src/puter-js/webpack.config.js new file mode 100644 index 00000000..4f160a0a --- /dev/null +++ b/src/puter-js/webpack.config.js @@ -0,0 +1,18 @@ +const path = require('path'); +const webpack = require('webpack'); + +console.log('ENV CHECK!!!', process.env.PUTER_ORIGIN, process.env.PUTER_API_ORIGIN); + +module.exports = { + entry: './src/index.js', + output: { + filename: 'puter.js', + path: path.resolve(__dirname, 'dist'), + }, + plugins: [ + new webpack.DefinePlugin({ + 'globalThis.PUTER_ORIGIN': JSON.stringify(process.env.PUTER_ORIGIN || 'https://puter.com'), + 'globalThis.PUTER_API_ORIGIN': JSON.stringify(process.env.PUTER_API_ORIGIN || 'https://api.puter.com'), + }), + ], +};