fix prod env
This commit is contained in:
parent
632e7979a2
commit
3006e85375
|
|
@ -108,7 +108,11 @@ export class TldrawDurableObject {
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Access-Control-Allow-Origin': '*'
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS, UPGRADE',
|
||||||
|
'Access-Control-Allow-Headers': 'Content-Type, Authorization, Upgrade, Connection',
|
||||||
|
'Access-Control-Max-Age': '86400',
|
||||||
|
'Access-Control-Allow-Credentials': 'true'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,24 +27,16 @@ const { preflight, corsify } = cors({
|
||||||
'https://jeffemmett-canvas.jeffemmett.workers.dev'
|
'https://jeffemmett-canvas.jeffemmett.workers.dev'
|
||||||
];
|
];
|
||||||
|
|
||||||
// Development patterns
|
// Always allow if no origin (like from a local file)
|
||||||
const devPatterns = [
|
if (!origin) return '*';
|
||||||
/^http:\/\/localhost:\d+$/,
|
|
||||||
/^http:\/\/127\.0\.0\.1:\d+$/,
|
|
||||||
/^http:\/\/192\.168\.\d+\.\d+:\d+$/,
|
|
||||||
/^http:\/\/169\.254\.\d+\.\d+:\d+$/,
|
|
||||||
/^http:\/\/10\.\d+\.\d+\.\d+:\d+$/
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!origin) return undefined;
|
// Check exact matches
|
||||||
|
|
||||||
// Check exact matches first
|
|
||||||
if (allowedOrigins.includes(origin)) {
|
if (allowedOrigins.includes(origin)) {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then check development patterns
|
// For development - check if it's a localhost or local IP
|
||||||
if (process.env.NODE_ENV === 'development' && devPatterns.some(pattern => pattern.test(origin))) {
|
if (origin.match(/^http:\/\/(localhost|127\.0\.0\.192\.168\.|169\.254\.|10\.)/)) {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue