From bbb4a2534bbde63ba5e22616a47a85170e76f7be Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 4 Dec 2025 00:02:50 -0600 Subject: [PATCH] Fix Deno Deploy so it works --- src/lib/deploy/DenoDeployAdapter.ts | 37 +++++++---------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/src/lib/deploy/DenoDeployAdapter.ts b/src/lib/deploy/DenoDeployAdapter.ts index 8fa61f5c..57f7665c 100644 --- a/src/lib/deploy/DenoDeployAdapter.ts +++ b/src/lib/deploy/DenoDeployAdapter.ts @@ -65,12 +65,9 @@ export class DenoDeployAdapter implements DeployAdapter { const assets: Record = {}; await this.collectFiles(distPath, '', assets); - // Step 3: Create deployment with assets - const deployment = await this.createDeployment(project.id, assets); - - // Step 4: Attach the deno.dev domain to the deployment + // Step 3: Create deployment with assets and domain const domain = `${project.name}.deno.dev`; - await this.attachDomain(deployment.id, `{project.name}.deno.dev`); + const deployment = await this.createDeployment(project.id, assets, domain); return { url: `https://${domain}`, @@ -140,18 +137,19 @@ export class DenoDeployAdapter implements DeployAdapter { private async createDeployment( projectId: string, - assets: Record + assets: Record, + domain: string ): Promise { const url = `${this.baseURL}/projects/${projectId}/deployments`; const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url; // Create a minimal server script that serves static files // For static sites, we use a simple file server entry point - const entryPointUrl = 'file:///src/main.ts'; + const entryPointUrl = 'main.ts'; // Add the entry point script that serves static files const serverScript = ` -import { serveDir } from "https://deno.land/std@0.208.0/http/file_server.ts"; +import { serveDir } from "jsr:@std/http/file-server"; Deno.serve((req) => { return serveDir(req, { @@ -163,7 +161,7 @@ Deno.serve((req) => { `; // Add the server script to assets - assets['src/main.ts'] = { + assets['main.ts'] = { kind: 'file', content: serverScript, encoding: 'utf-8', @@ -182,6 +180,8 @@ Deno.serve((req) => { lockFileUrl: null, compilerOptions: null, envVars: {}, + // Attach domain during deployment creation instead of separately + domains: [domain], }), }); @@ -193,25 +193,6 @@ Deno.serve((req) => { return response.json(); } - private async attachDomain(deploymentId: string, domain: string): Promise { - const url = `${this.baseURL}/deployments/${deploymentId}/domains/${encodeURIComponent(domain)}`; - const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url; - - const response = await fetch(targetUrl, { - method: 'PUT', - headers: { - 'Authorization': `Bearer ${this.apiKey}`, - 'Content-Type': 'application/json', - }, - }); - - if (!response.ok) { - const errorText = await response.text().catch(() => 'Unknown error'); - // Don't throw on domain attachment failure - deployment still succeeded - console.warn(`Failed to attach domain: ${response.status} ${response.statusText}. ${errorText}`); - } - } - private async collectFiles( dirPath: string, relativePath: string,