mirror of
https://github.com/HeyPuter/puter.git
synced 2025-12-30 09:40:00 -06:00
Merge pull request #1606 from HeyPuter/DS/main
feat: allow setting puter origin via globalThis variables
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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'),
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user