From c33fcfec0f43c7280773ff625bc0042bface4f53 Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Thu, 27 Nov 2025 17:05:33 +0800 Subject: [PATCH] Add Deno Deploy handler to workflow Introduces a step in the GitHub Actions workflow to create a Deno Deploy handler (deno.js) for deployments. The handler adapts the main request handler for Deno's environment, extracting environment variables and providing minimal context support. --- .github/workflows/sync.yml | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 526b5b4..f5733b6 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -367,6 +367,75 @@ jobs: export { default, config } from '../../api/index.js'; EOF + - name: Create Deno Deploy handler + run: | + cd /tmp/functions-conversion + cat > deno.js << 'EOF' + /** + * Xget - High-performance acceleration engine for developer resources + * Copyright (C) 2025 Xi Xu + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + import { handleRequest } from './src/index.js'; + + /** + * Deno Deploy handler. + * + * This is the entry point for Deno Deploy deployments. It uses the + * standard Deno.serve() API to handle incoming HTTP requests. + * + * @param {Request} request - Standard Web API Request object + * @returns {Promise} Standard Web API Response + * + * @example + * // Deno Deploy invokes automatically: + * // Deno.serve((request) => handler(request)) + */ + async function handler(request) { + // Extract environment variables from Deno.env + const env = { + TIMEOUT_SECONDS: Deno.env.get('TIMEOUT_SECONDS'), + MAX_RETRIES: Deno.env.get('MAX_RETRIES'), + RETRY_DELAY_MS: Deno.env.get('RETRY_DELAY_MS'), + CACHE_DURATION: Deno.env.get('CACHE_DURATION'), + ALLOWED_METHODS: Deno.env.get('ALLOWED_METHODS'), + ALLOWED_ORIGINS: Deno.env.get('ALLOWED_ORIGINS'), + MAX_PATH_LENGTH: Deno.env.get('MAX_PATH_LENGTH'), + }; + + // Create minimal ExecutionContext-like object + // Deno Deploy doesn't support waitUntil, so cache writes are synchronous + const ctx = { + waitUntil: (promise) => { + // No-op on Deno: background tasks not supported + console.warn('waitUntil is not supported in Deno Deploy'); + }, + passThroughOnException: () => { + console.warn('passThroughOnException is not supported in Deno Deploy'); + } + }; + + // Delegate to the main request handler + return handleRequest(request, env, ctx); + } + + // Start the server + Deno.serve(handler); + EOF + - name: Export handleRequest from src/index.js run: | cd /tmp/functions-conversion