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>
59 lines
2.2 KiB
TypeScript
59 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { API_ENDPOINT, dataPath, moveOldStoredKeys, sitePath } from '../../src/core/site';
|
|
|
|
function memoryStore(initial: Record<string, string>) {
|
|
const items = new Map(Object.entries(initial));
|
|
return {
|
|
items,
|
|
get length() {
|
|
return items.size;
|
|
},
|
|
key: (i: number) => [...items.keys()][i] ?? null,
|
|
getItem: (key: string) => items.get(key) ?? null,
|
|
setItem: (key: string, value: string) => void items.set(key, value),
|
|
removeItem: (key: string) => void items.delete(key),
|
|
};
|
|
}
|
|
|
|
describe('site', () => {
|
|
it('serves the API and the data files under /feuerwerk/', () => {
|
|
expect(API_ENDPOINT).toBe('/feuerwerk/api/index.php');
|
|
expect(dataPath('textures')).toBe('/feuerwerk/data/textures');
|
|
});
|
|
|
|
it('takes the path from the folder of the open page', () => {
|
|
expect(sitePath('/feuerwerk/')).toBe('/feuerwerk/');
|
|
expect(sitePath('/feuerwerk/index.html')).toBe('/feuerwerk/');
|
|
expect(sitePath('/feuerwerk/play.html')).toBe('/feuerwerk/');
|
|
expect(sitePath('/')).toBe('/');
|
|
expect(sitePath('/play.html')).toBe('/');
|
|
});
|
|
|
|
it('moves the keys stored under the old name and leaves the others alone', () => {
|
|
const store = memoryStore({
|
|
'game-maker.panel-sizes': '{"left":300}',
|
|
'game-maker.saves.p1.Savegame': '{"Lives":2}',
|
|
'other-site.key': 'x',
|
|
});
|
|
expect(moveOldStoredKeys(store)).toBe(2);
|
|
expect(Object.fromEntries(store.items)).toEqual({
|
|
'feuerwerk.panel-sizes': '{"left":300}',
|
|
'feuerwerk.saves.p1.Savegame': '{"Lives":2}',
|
|
'other-site.key': 'x',
|
|
});
|
|
});
|
|
|
|
it('keeps a value the new name already has and drops the old one', () => {
|
|
const store = memoryStore({ 'game-maker.general-settings': 'old', 'feuerwerk.general-settings': 'new' });
|
|
expect(moveOldStoredKeys(store)).toBe(0);
|
|
expect(Object.fromEntries(store.items)).toEqual({ 'feuerwerk.general-settings': 'new' });
|
|
});
|
|
|
|
it('does nothing the second time', () => {
|
|
const store = memoryStore({ 'game-maker.folded-sections': '[]' });
|
|
moveOldStoredKeys(store);
|
|
expect(moveOldStoredKeys(store)).toBe(0);
|
|
expect(Object.fromEntries(store.items)).toEqual({ 'feuerwerk.folded-sections': '[]' });
|
|
});
|
|
});
|