mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-28 15:51:29 +08:00
53ca110218
Flatten the instance `runtime` object into two fields: `runtime` (the JS engine,
node | workerd) and `platform` (the deployment host). The About page shows each
as its own row with friendly labels (e.g. "workerd" + "Cloudflare Workers",
"Node.js" + "Docker").
- Detect the platform from the entry file (entry === target): each serverless
entry declares it; entry-node sniffs Cloud Run (K_SERVICE) / Docker
(ZPAN_RUNTIME, set in the Dockerfile) / bare node. Cloudflare is detected from
the D1 binding.
- Decouple the cloud payload: zpan-cloud-sdk fixes runtime { provider, target },
so CloudInstanceInfo keeps that shape and buildCloudInstanceInfo maps to it;
buildInstanceInfo serves the richer flat shape to the About API.
- Migrate PostHog instance telemetry to the runtime/platform shape and merge the
duplicate runtimeInfo in licensing-admin into the shared one.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
import type { HttpRequest, InvocationContext } from '@azure/functions'
|
|
import { app } from '@azure/functions'
|
|
import { serveStatic } from '@hono/node-server/serve-static'
|
|
import { Hono } from 'hono'
|
|
import { createBootstrap } from './bootstrap'
|
|
import { createLibsqlPlatform } from './platform/libsql'
|
|
import { setDeployPlatform } from './runtime-platform'
|
|
|
|
setDeployPlatform('azure-functions')
|
|
|
|
const TURSO_DATABASE_URL = process.env.TURSO_DATABASE_URL
|
|
if (!TURSO_DATABASE_URL) {
|
|
throw new Error('TURSO_DATABASE_URL is required for the Azure Functions deployment.')
|
|
}
|
|
|
|
const platform = await createLibsqlPlatform({
|
|
TURSO_DATABASE_URL,
|
|
TURSO_AUTH_TOKEN: process.env.TURSO_AUTH_TOKEN,
|
|
})
|
|
|
|
const apiApp = await createBootstrap(platform)
|
|
|
|
const server = new Hono()
|
|
server.route('/', apiApp)
|
|
server.use('/*', serveStatic({ root: './dist' }))
|
|
server.get('/*', serveStatic({ root: './dist', path: 'index.html' }))
|
|
|
|
app.http('zpan', {
|
|
methods: ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT'],
|
|
authLevel: 'anonymous',
|
|
route: '{*path}',
|
|
handler: async (request: HttpRequest, _context: InvocationContext): Promise<Response> => {
|
|
// Construct a standards-compliant Request so Hono body-reading works correctly
|
|
// on POST/PUT/PATCH routes. Azure HttpRequest v4 has additional properties and
|
|
// a single-read stream; wrapping it avoids silent breakage on body-reading routes.
|
|
// The body cast and duplex option are required for Node 22's undici-based fetch.
|
|
const hasBody = request.method !== 'GET' && request.method !== 'HEAD'
|
|
const webReq = new Request(request.url, {
|
|
method: request.method,
|
|
headers: request.headers,
|
|
body: hasBody ? (request.body as BodyInit) : undefined,
|
|
...(hasBody ? { duplex: 'half' } : {}),
|
|
} as RequestInit)
|
|
return server.fetch(webReq)
|
|
},
|
|
})
|