mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-23 19:49:56 +01:00
web: add support for switching release tracks
we make use of Cloudflare Pages Functions to redirect to the beta site if a certain cookie is present. This ensures seamless switching between release tracks.
This commit is contained in:
committed by
Abdullah Atta
parent
efa73a1c32
commit
725f3c3522
1383
apps/web/package-lock.json
generated
1383
apps/web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -85,6 +85,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.22.5",
|
||||
"@cloudflare/workers-types": "^4.20250224.0",
|
||||
"@playwright/test": "1.48.2",
|
||||
"@swc/plugin-react-remove-properties": "^6.0.2",
|
||||
"@trpc/server": "10.45.2",
|
||||
@@ -131,6 +132,7 @@
|
||||
"start:test": "serve -s build/ -p 3000",
|
||||
"build": "cross-env PLATFORM=web vite build",
|
||||
"build:test": "cross-env PLATFORM=web TEST=true vite build",
|
||||
"build:beta": "cross-env PLATFORM=web BETA=true vite build",
|
||||
"build:desktop": "cross-env PLATFORM=desktop vite build",
|
||||
"analyze": "cross-env ANALYZING=true PLATFORM=web vite build",
|
||||
"test": "playwright test -u",
|
||||
|
||||
53
apps/web/public/functions/_middleware.ts
Normal file
53
apps/web/public/functions/_middleware.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
This file is part of the Notesnook project (https://notesnook.com/)
|
||||
|
||||
Copyright (C) 2023 Streetwriters (Private) Limited
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function isBeta(cookie: string) {
|
||||
console.log("Checking cookie:", cookie);
|
||||
const releaseTrack = cookie
|
||||
.split("; ")
|
||||
.find((row) => row.startsWith("release-track="))
|
||||
?.split("=")[1];
|
||||
return releaseTrack === "beta";
|
||||
}
|
||||
|
||||
interface Env {
|
||||
BETA_BASE_URL: string;
|
||||
}
|
||||
|
||||
export const onRequest: PagesFunction<Env> = async ({ request, env, next }) => {
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const response = await (async () => {
|
||||
if (isBeta(request.headers.get("Cookie") || "")) {
|
||||
const betaUrl = new URL(env.BETA_BASE_URL);
|
||||
betaUrl.pathname = url.pathname;
|
||||
betaUrl.search = url.search;
|
||||
console.log("Fetching asset from beta URL:", betaUrl.toString());
|
||||
const asset = await fetch(betaUrl);
|
||||
return new Response(asset.body, asset);
|
||||
} else {
|
||||
return await next();
|
||||
}
|
||||
})();
|
||||
return response;
|
||||
} catch (thrown) {
|
||||
console.error("Error occurred:", thrown);
|
||||
return new Response(thrown);
|
||||
}
|
||||
};
|
||||
10
apps/web/public/functions/tsconfig.json
Normal file
10
apps/web/public/functions/tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "CommonJS",
|
||||
"lib": ["ES2020"],
|
||||
"types": ["@cloudflare/workers-types"],
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,43 @@ export const AboutSettings: SettingsGroup[] = [
|
||||
];
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "release-track",
|
||||
title: strings.releaseTrack(),
|
||||
description: strings.releaseTrackDesc(),
|
||||
components: [
|
||||
{
|
||||
type: "dropdown",
|
||||
options: [
|
||||
{
|
||||
title: strings.stable(),
|
||||
value: "stable"
|
||||
},
|
||||
{
|
||||
title: strings.beta(),
|
||||
value: "beta"
|
||||
}
|
||||
],
|
||||
selectedOption: () => {
|
||||
return (
|
||||
document.cookie
|
||||
.split("; ")
|
||||
.find((row) => row.startsWith("release-track="))
|
||||
?.split("=")[1] || "stable"
|
||||
);
|
||||
},
|
||||
async onSelectionChanged(value) {
|
||||
document.cookie = `release-track=${value}; Secure`;
|
||||
const registrations =
|
||||
(await navigator.serviceWorker?.getRegistrations()) || [];
|
||||
for (const registration of registrations) {
|
||||
await registration.unregister();
|
||||
}
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
key: "source-code",
|
||||
title: strings.sourceCode(),
|
||||
|
||||
@@ -38,7 +38,7 @@ const gitHash = (() => {
|
||||
}
|
||||
})();
|
||||
const appVersion = version.replaceAll(".", "").replace("-beta", "");
|
||||
const isBeta = version.endsWith("-beta");
|
||||
const isBeta = process.env.BETA === "true";
|
||||
const isTesting =
|
||||
process.env.TEST === "true" || process.env.NODE_ENV === "development";
|
||||
const isDesktop = process.env.PLATFORM === "desktop";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -384,7 +384,6 @@ export const strings = {
|
||||
other: `v${version} has been released`
|
||||
}),
|
||||
readReleaseNotes: () => t`Read full release notes on Github`,
|
||||
beta: () => t`BETA`,
|
||||
settings: () => t`Settings`,
|
||||
notLoggedIn: () => t`Not logged in`,
|
||||
never: () => t`Never`,
|
||||
@@ -2434,5 +2433,9 @@ Use this if changes from other devices are not appearing on this device. This wi
|
||||
actionsForNotebook: (title: string) => t`Actions for notebook: ${title}`,
|
||||
actionsForTag: (title: string) => t`Actions for tag: ${title}`,
|
||||
recents: () => t`Recents`,
|
||||
removeFromRecents: () => t`Remove from recents`
|
||||
removeFromRecents: () => t`Remove from recents`,
|
||||
releaseTrack: () => t`Release track`,
|
||||
releaseTrackDesc: () => t`Select the release track for Notesnook.`,
|
||||
stable: () => t`Stable`,
|
||||
beta: () => t`Beta`
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user