standalone: add ability to change assets host versions
This commit is contained in:
@@ -58,7 +58,7 @@ Example:
|
||||
></cap-widget>
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
> [!TIP]
|
||||
> Does generating challenges not work? Make sure your server is publicly accessible and that `CORS_ORIGIN` is set correctly to allow requests from your website's origin.
|
||||
|
||||
### Server-side
|
||||
@@ -131,4 +131,6 @@ And by setting `window.CAP_CUSTOM_WASM_URL` to the path of the `cap_wasm_bg.wasm
|
||||
window.CAP_CUSTOM_WASM_URL = "https://<server url>/assets/cap_wasm_bg.wasm";
|
||||
```
|
||||
|
||||
By default, these fetch from `process.env.CACHE_HOST`. You can change this by setting the `CACHE_HOST` environment variable when running the server. If you don't set it, it defaults to `https://cdn.jsdelivr.net`. You can also set it to `disable` to disable the assets server entirely.
|
||||
You can and should also change the version of the widget and WASM files by setting `process.env.WIDGET_VERSION` and `process.env.WASM_VERSION`. This will help you avoid breaking changes in the future.
|
||||
|
||||
By default, these fetch from `process.env.CACHE_HOST`. You can change this by setting the `CACHE_HOST` environment variable when running the server. If you don't set it, it defaults to `https://cdn.jsdelivr.net`. You can also set it to `disable` to disable the assets server entirely.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cap-standalone",
|
||||
"version": "1.0.16",
|
||||
"version": "1.0.17",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "bun run --watch src/index.js",
|
||||
|
||||
+12
-12
@@ -61,24 +61,24 @@ const updateCache = async () => {
|
||||
if (!(currentTime - lastUpdate > updateInterval)) return;
|
||||
|
||||
const CACHE_HOST = process.env.CACHE_HOST || "https://cdn.jsdelivr.net";
|
||||
|
||||
if (CACHE_HOST === "disable") return;
|
||||
|
||||
const WIDGET_VERSION = process.env.WIDGET_VERSION || "latest";
|
||||
const WASM_VERSION = process.env.WASM_VERSION || "latest";
|
||||
|
||||
try {
|
||||
const [widgetSource, floatingSource, wasmSource, wasmLoaderSource] =
|
||||
await Promise.all([
|
||||
fetch(`${CACHE_HOST}/npm/@cap.js/widget@latest`).then((r) =>
|
||||
r.text()
|
||||
fetch(`${CACHE_HOST}/npm/@cap.js/widget@${WIDGET_VERSION}`).then((r) => r.text()),
|
||||
fetch(`${CACHE_HOST}/npm/@cap.js/widget@${WIDGET_VERSION}/cap-floating.min.js`).then(
|
||||
(r) => r.text()
|
||||
),
|
||||
fetch(`${CACHE_HOST}/npm/@cap.js/wasm@${WASM_VERSION}/browser/cap_wasm_bg.wasm`).then(
|
||||
(r) => r.arrayBuffer()
|
||||
),
|
||||
fetch(`${CACHE_HOST}/npm/@cap.js/wasm@${WASM_VERSION}/browser/cap_wasm.min.js`).then(
|
||||
(r) => r.text()
|
||||
),
|
||||
fetch(
|
||||
`${CACHE_HOST}/npm/@cap.js/widget/cap-floating.min.js`
|
||||
).then((r) => r.text()),
|
||||
fetch(
|
||||
`${CACHE_HOST}/npm/@cap.js/wasm/browser/cap_wasm_bg.wasm`
|
||||
).then((r) => r.arrayBuffer()),
|
||||
fetch(
|
||||
`${CACHE_HOST}/npm/@cap.js/wasm/browser/cap_wasm.min.js`
|
||||
).then((r) => r.text()),
|
||||
]);
|
||||
|
||||
cacheConfig["lastUpdate"] = currentTime;
|
||||
|
||||
Reference in New Issue
Block a user