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'),
|
||||
|
||||
Reference in New Issue
Block a user