Gate Studio frontend by workspace and isolate browser catalog state
This commit is contained in:
+12
-1
@@ -9,6 +9,12 @@ const { createImageHandler } = require('./images.cjs');
|
||||
const { createStaticHandler } = require('./static.cjs');
|
||||
|
||||
function createStudioServer(config) {
|
||||
let loginUrl = null;
|
||||
if (config.loginUrl) {
|
||||
const parsed = new URL(config.loginUrl);
|
||||
if (!['https:', 'http:'].includes(parsed.protocol) || parsed.username || parsed.password || parsed.hash) throw new Error('Invalid public login URL');
|
||||
loginUrl = parsed.href;
|
||||
}
|
||||
const resolveWorkspace = createWorkspaceResolver({ authMeUrl: config.authMeUrl, clientMeUrl: config.clientMeUrl });
|
||||
const store = createStore(config.dataDirectory);
|
||||
const scrape = createScraper({ fetchPublic: createPublicFetcher(config.fetchLimits), ...config.importLimits });
|
||||
@@ -18,6 +24,10 @@ function createStudioServer(config) {
|
||||
const server = http.createServer({ maxHeaderSize: 16384 }, async (req, res) => {
|
||||
try {
|
||||
const pathname = new URL(req.url, config.publicOrigin).pathname;
|
||||
if (pathname === '/api/studio-config' && req.method === 'GET') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff' });
|
||||
return res.end(JSON.stringify({ loginUrl }));
|
||||
}
|
||||
if (pathname === '/health' && ['GET', 'HEAD'].includes(req.method)) {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
|
||||
return res.end(req.method === 'HEAD' ? undefined : JSON.stringify({ ok: true, service: 'aura-studio' }));
|
||||
@@ -37,7 +47,7 @@ function createStudioServer(config) {
|
||||
|
||||
if (require.main === module) {
|
||||
try {
|
||||
const required = ['STUDIO_PUBLIC_ORIGIN', 'STUDIO_AUTH_ME_URL', 'STUDIO_CLIENT_ME_URL', 'STUDIO_DATA_DIR'];
|
||||
const required = ['STUDIO_PUBLIC_ORIGIN', 'STUDIO_LOGIN_URL', 'STUDIO_AUTH_ME_URL', 'STUDIO_CLIENT_ME_URL', 'STUDIO_DATA_DIR'];
|
||||
if (required.some(name => !process.env[name])) throw new Error('Required Studio service configuration is missing');
|
||||
const port = Number(process.env.PORT || 3000);
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error('Invalid Studio port');
|
||||
@@ -49,6 +59,7 @@ if (require.main === module) {
|
||||
}
|
||||
const server = createStudioServer({
|
||||
publicOrigin: process.env.STUDIO_PUBLIC_ORIGIN,
|
||||
loginUrl: process.env.STUDIO_LOGIN_URL,
|
||||
authMeUrl: process.env.STUDIO_AUTH_ME_URL, clientMeUrl: process.env.STUDIO_CLIENT_ME_URL,
|
||||
dataDirectory: process.env.STUDIO_DATA_DIR,
|
||||
publicDirectory: process.env.STUDIO_PUBLIC_DIR || path.join(__dirname, '../public'),
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ const { createHash } = require('node:crypto');
|
||||
const { gzipSync } = require('node:zlib');
|
||||
|
||||
const MIME = { '.html': 'text/html; charset=utf-8', '.js': 'application/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.json': 'application/json; charset=utf-8', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.woff': 'font/woff', '.woff2': 'font/woff2' };
|
||||
const ROOT_FILES = new Set(['index.html', 'app.js', 'style.css', 'sw.js', 'manifest.json', 'gt_full_catalog.json']);
|
||||
const ROOT_FILES = new Set(['index.html', 'app.js', 'workspace.js', 'style.css', 'sw.js', 'manifest.json', 'gt_full_catalog.json']);
|
||||
|
||||
function createStaticHandler(publicDirectory, { maxCacheBytes = 16 * 1024 * 1024 } = {}) {
|
||||
const root = path.resolve(publicDirectory), cache = new Map();
|
||||
|
||||
Reference in New Issue
Block a user