mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-27 18:09:10 +00:00
fix: resolve path to public assets in cloud
This commit is contained in:
committed by
Carlos Valente
parent
cc48ac8fd3
commit
23298bbe85
@@ -3,14 +3,14 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<base href="/" />
|
<base href="/" />
|
||||||
<link rel="icon" href="/favicon.ico" />
|
<link rel="icon" href="favicon.ico" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="theme-color" content="#101010" />
|
<meta name="theme-color" content="#101010" />
|
||||||
<meta name="ontime" content="ontime - time keeping for live events" />
|
<meta name="ontime" content="ontime - time keeping for live events" />
|
||||||
<link rel="apple-touch-icon" href="/ontime-logo.png" />
|
<link rel="apple-touch-icon" href="ontime-logo.png" />
|
||||||
<link rel="icon" type="image/png" href="/ontime-logo.png" />
|
<link rel="icon" type="image/png" href="ontime-logo.png" />
|
||||||
<link rel="manifest" href="/site.webmanifest" />
|
<link rel="manifest" href="site.webmanifest" />
|
||||||
<link rel="manifest" href="/manifest.json" />
|
<link rel="manifest" href="manifest.json" />
|
||||||
<meta name="robots" content="noindex" />
|
<meta name="robots" content="noindex" />
|
||||||
<title>ontime</title>
|
<title>ontime</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
"type": "image/png"
|
"type": "image/png"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"scope": "/",
|
"scope": "./",
|
||||||
"start_url": "/",
|
"start_url": "./",
|
||||||
"display": "",
|
"display": "",
|
||||||
"theme_color": "#121212",
|
"theme_color": "#121212",
|
||||||
"background_color": "#ffffff"
|
"background_color": "#ffffff"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "",
|
"name": "",
|
||||||
"short_name": "",
|
"short_name": "",
|
||||||
"icons": [{ "src": "/ontime-logo.png", "sizes": "295x295", "type": "image/png" }],
|
"icons": [{ "src": "ontime-logo.png", "sizes": "295x295", "type": "image/png" }],
|
||||||
"theme_color": "#2B5ABC",
|
"theme_color": "#2B5ABC",
|
||||||
"background_color": "#101010",
|
"background_color": "#101010",
|
||||||
"display": "standalone"
|
"display": "standalone"
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import { isPublicAssetRequest } from '../authenticate.js';
|
||||||
|
|
||||||
|
describe('isPublicAssetRequest()', () => {
|
||||||
|
it('allows root public assets without a prefix', () => {
|
||||||
|
expect(isPublicAssetRequest('/site.webmanifest', '')).toBe(true);
|
||||||
|
expect(isPublicAssetRequest('/manifest.json', '')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows prefixed public assets in cloud deployments', () => {
|
||||||
|
expect(isPublicAssetRequest('/stage-hash/site.webmanifest', '/stage-hash')).toBe(true);
|
||||||
|
expect(isPublicAssetRequest('/stage-hash/ontime-logo.png?cache=1', '/stage-hash')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps non-public paths protected', () => {
|
||||||
|
expect(isPublicAssetRequest('/stage-hash/data', '/stage-hash')).toBe(false);
|
||||||
|
expect(isPublicAssetRequest('/backstage', '')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -21,6 +21,20 @@ const publicAssets = new Set([
|
|||||||
'/site.webmanifest',
|
'/site.webmanifest',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
export function isPublicAssetRequest(originalUrl: string, prefix: string): boolean {
|
||||||
|
const pathname = originalUrl.split('?')[0];
|
||||||
|
|
||||||
|
if (publicAssets.has(pathname)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefix && pathname.startsWith(prefix)) {
|
||||||
|
return publicAssets.has(pathname.slice(prefix.length) || '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a login router with the provided prefix
|
* Creates a login router with the provided prefix
|
||||||
* @param {string} prefix - Prefix is used for the client hashes in Ontime Cloud
|
* @param {string} prefix - Prefix is used for the client hashes in Ontime Cloud
|
||||||
@@ -81,7 +95,7 @@ export function makeAuthenticateMiddleware(prefix: string) {
|
|||||||
|
|
||||||
function authenticateAndRedirect(req: Request, res: Response, next: NextFunction) {
|
function authenticateAndRedirect(req: Request, res: Response, next: NextFunction) {
|
||||||
// Allow access to specific public assets without authentication
|
// Allow access to specific public assets without authentication
|
||||||
if (publicAssets.has(req.originalUrl)) {
|
if (isPublicAssetRequest(req.originalUrl, prefix)) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user