The subdomain proxies to the same folder, but the build had the path /feuerwerk/ baked in. On feuerwerk.nockal.com the page loaded its assets, the API and the data URLs from /feuerwerk/... and got 404. The session cookie had Path=/feuerwerk/, so the browser would never have sent it to /api/ there either. - site.ts takes the base path from the folder of the open page: /feuerwerk/ on nockal.com, / on the subdomain. Release links point at the address you are working on. - vite.config.ts builds with a relative base. The copy plugin rewrites the pages to ./dist/assets/ and stops the build if it finds nothing to rewrite. The dev server now runs at http://localhost:5175/. - Auth.php sets the cookie without a Path, so it belongs to the API folder the browser sees. Sign-in and sign-out also clear the old /feuerwerk/ cookie, otherwise it would keep signing in after a logout. Existing sessions stay valid. - README: the new dev server address. Tests: - curl on both addresses: pages, JS, CSS and API 200 - sign-in, session, sign-out on both addresses - e2e 70 against both addresses: 13/13 each, no CSP violation - tsc, lint, prettier clean, site and releases tests 14/14 - PHP tests 7 of 8 files green, videos.test.php fails only because the web-php-fpm container has no ffmpeg Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
/**
|
|
* The path the site is served under: the editor, the play page, the API and every data file. It
|
|
* is the folder of the open page, so one build answers at https://nockal.com/feuerwerk/ and at
|
|
* https://feuerwerk.nockal.com/ alike. Away from a page (Node, the tests) it is the nginx path.
|
|
*/
|
|
export const SITE_PATH = sitePath(typeof location === 'undefined' ? undefined : location.pathname);
|
|
|
|
/** The folder of a page path: `/feuerwerk/play.html` and `/feuerwerk/` give `/feuerwerk/`. */
|
|
export function sitePath(pagePath: string | undefined): string {
|
|
if (pagePath === undefined) return '/feuerwerk/';
|
|
return pagePath.slice(0, pagePath.lastIndexOf('/') + 1);
|
|
}
|
|
|
|
/** The API's one entry point. */
|
|
export const API_ENDPOINT = `${SITE_PATH}api/index.php`;
|
|
|
|
/** Where the uploaded files of one kind are served, e.g. `dataPath('textures')`. */
|
|
export function dataPath(kind: string): string {
|
|
return `${SITE_PATH}data/${kind}`;
|
|
}
|
|
|
|
/** The prefix of every `localStorage` key while the editor was called Game Maker. */
|
|
const OLD_KEY_PREFIX = 'game-maker.';
|
|
const KEY_PREFIX = 'feuerwerk.';
|
|
|
|
type KeyStore = Pick<Storage, 'length' | 'key' | 'getItem' | 'setItem' | 'removeItem'>;
|
|
|
|
/**
|
|
* Moves what a browser kept under the old name to the new one: settings, panel sizes, folds and
|
|
* saves survive the rename. A key the new name already has keeps its value. Answers how many moved.
|
|
*/
|
|
export function moveOldStoredKeys(storage: KeyStore): number {
|
|
const old: string[] = [];
|
|
for (let i = 0; i < storage.length; i++) {
|
|
const key = storage.key(i);
|
|
if (key?.startsWith(OLD_KEY_PREFIX)) old.push(key);
|
|
}
|
|
let moved = 0;
|
|
for (const key of old) {
|
|
const value = storage.getItem(key);
|
|
const renamed = KEY_PREFIX + key.slice(OLD_KEY_PREFIX.length);
|
|
if (value !== null && storage.getItem(renamed) === null) {
|
|
storage.setItem(renamed, value);
|
|
moved++;
|
|
}
|
|
storage.removeItem(key);
|
|
}
|
|
return moved;
|
|
}
|