diff --git a/src/puter-js/README.md b/src/puter-js/README.md
index 0ebc8964..eccd6e0b 100644
--- a/src/puter-js/README.md
+++ b/src/puter-js/README.md
@@ -88,6 +88,21 @@ puter.ai.chat('What color was Napoleon\'s white horse?').then(response => {
+## Setting Custom Origins
+By default puter.js uses the official Puter API and GUI origins. You can customize these origins by setting global variables before importing the SDK like so:
+
+```js
+// For API origin
+globalThis.PUTER_API_ORIGIN = 'https://custom-api.puter.com';
+// For GUI origin
+globalThis.PUTER_ORIGIN = 'https://custom-gui.puter.com';
+
+import {puter} from '@heyputer/puter.js'; // or however you import it for your env
+```
+
+
+---
+
## Documentation & Community
- [Developer Site](https://developer.puter.com)
diff --git a/src/puter-js/package.json b/src/puter-js/package.json
index 2ccef92e..0532e31a 100644
--- a/src/puter-js/package.json
+++ b/src/puter-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@heyputer/puter.js",
- "version": "2.0.12",
+ "version": "2.0.13",
"description": "Puter.js - A JavaScript library for interacting with Puter services.",
"main": "src/index.js",
"types": "index.d.ts",
diff --git a/src/puter-js/src/index.js b/src/puter-js/src/index.js
index 9228fe66..0a6335dd 100644
--- a/src/puter-js/src/index.js
+++ b/src/puter-js/src/index.js
@@ -45,8 +45,22 @@ const puterInit = (function() {
// 'web' means the SDK is running in a 3rd-party website.
env;
- defaultAPIOrigin = globalThis.PUTER_API_ORIGIN ?? 'https://api.puter.com';
- defaultGUIOrigin = globalThis.PUTER_ORIGIN ?? 'https://puter.com';
+ #defaultAPIOrigin = 'https://api.puter.com';
+ #defaultGUIOrigin = 'https://puter.com';
+
+ get defaultAPIOrigin() {
+ return globalThis.PUTER_API_ORIGIN || globalThis.PUTER_API_ORIGIN_ENV || this.#defaultAPIOrigin;
+ }
+ set defaultAPIOrigin(v) {
+ this.#defaultAPIOrigin = v;
+ }
+
+ get defaultGUIOrigin() {
+ return globalThis.PUTER_ORIGIN || globalThis.PUTER_ORIGIN_ENV || this.#defaultGUIOrigin;
+ }
+ set defaultGUIOrigin(v) {
+ this.#defaultGUIOrigin = v;
+ }
// 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/src/init.cjs b/src/puter-js/src/init.cjs
index fa081263..69ddf9ac 100644
--- a/src/puter-js/src/init.cjs
+++ b/src/puter-js/src/init.cjs
@@ -7,7 +7,10 @@ const { resolve } = require('node:path');
* @returns {import('../index').puter} The `puter` object from puter.js
*/
const init = (authToken) => {
- const goodContext = {};
+ const goodContext = {
+ PUTER_API_ORIGIN: globalThis.PUTER_API_ORIGIN,
+ PUTER_ORIGIN: globalThis.PUTER_ORIGIN,
+ };
Object.getOwnPropertyNames(globalThis).forEach(name => {
try {
goodContext[name] = globalThis[name];
diff --git a/src/puter-js/webpack.config.js b/src/puter-js/webpack.config.js
index bacc727b..2fea0230 100644
--- a/src/puter-js/webpack.config.js
+++ b/src/puter-js/webpack.config.js
@@ -18,8 +18,8 @@ export default {
},
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'),
+ 'globalThis.PUTER_ORIGIN_ENV': JSON.stringify(process.env.PUTER_ORIGIN || 'https://puter.com'),
+ 'globalThis.PUTER_API_ORIGIN_ENV': JSON.stringify(process.env.PUTER_API_ORIGIN || 'https://api.puter.com'),
}),
],
};