Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ interface StudioTransactionRequest {
}
type StudioRequest = StudioQueryRequest | StudioTransactionRequest;
interface StudioOptions {
enforceId?: string;
disableHomepage?: boolean;
basicAuth?: {
username: string;
password: string;
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,20 @@ export async function studio(request, doNamespace, options) {
if (request.method === 'GET') {
// This is where we render the interface
const url = new URL(request.url);
const stubId = url.searchParams.get('id');
const stubId = options?.enforceId ?? url.searchParams.get('id');
if (!stubId) {
if (options?.disableHomepage) {
return new Response('Not found', { status: 404 });
}
return new Response(createHomepageInterface(), { headers: { 'Content-Type': 'text/html' } });
}
return new Response(createStudioInterface(stubId), { headers: { 'Content-Type': 'text/html' } });
}
else if (request.method === 'POST') {
const body = (await request.json());
if (body.type === 'query' || body.type === 'transaction') {
const stubId = doNamespace.idFromName(body.id);
const id = options?.enforceId ?? body.id;
const stubId = doNamespace.idFromName(id);
const stub = doNamespace.get(stubId);
try {
// @ts-ignore - accessing __studio method that we know exists
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@outerbase/browsable-durable-object",
"version": "0.1.1",
"version": "0.2.0",
"type": "module",
"module": "./dist/index.js",
"main": "./dist/index.js",
Expand Down Expand Up @@ -34,4 +34,4 @@
"typescript": "^5.5.2",
"wrangler": "^3.114.0"
}
}
}
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ function createStudioInterface(stubId: string) {
}

interface StudioOptions {
enforceId?: string;
disableHomepage?: boolean;
basicAuth?: {
username: string;
password: string;
Expand Down Expand Up @@ -433,9 +435,12 @@ export async function studio(request: Request, doNamespace: DurableObjectNamespa
if (request.method === 'GET') {
// This is where we render the interface
const url = new URL(request.url);
const stubId = url.searchParams.get('id');
const stubId = options?.enforceId ?? url.searchParams.get('id');

if (!stubId) {
if (options?.disableHomepage) {
return new Response('Not found', { status: 404 });
}
return new Response(createHomepageInterface(), { headers: { 'Content-Type': 'text/html' } });
}

Expand All @@ -444,7 +449,8 @@ export async function studio(request: Request, doNamespace: DurableObjectNamespa
const body = (await request.json()) as StudioRequest;

if (body.type === 'query' || body.type === 'transaction') {
const stubId = doNamespace.idFromName(body.id);
const id = options?.enforceId ?? body.id;
const stubId = doNamespace.idFromName(id);
const stub = doNamespace.get(stubId);

try {
Expand All @@ -463,4 +469,4 @@ export async function studio(request: Request, doNamespace: DurableObjectNamespa
}

return new Response('Method not allowed');
}
}