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
15 changes: 15 additions & 0 deletions src/puter-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ puter.ai.chat('What color was Napoleon\'s white horse?').then(response => {

<br>

## 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
```
<br>

---

## Documentation & Community

- [Developer Site](https://developer.puter.com)
Expand Down
2 changes: 1 addition & 1 deletion src/puter-js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 16 additions & 2 deletions src/puter-js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/puter-js/src/init.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/puter-js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}),
],
};