@flightdev/adapter-azure 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +253 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Flight Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { FlightAdapter } from '@flightdev/core/adapters';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Flight Adapter - Azure Functions
|
|
5
|
+
*
|
|
6
|
+
* Deploy to Azure Functions serverless platform.
|
|
7
|
+
* Supports HTTP triggers with Node.js/TypeScript v4 programming model.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { defineConfig } from '@flightdev/core';
|
|
12
|
+
* import azure from '@flightdev/adapter-azure';
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* adapter: azure({
|
|
16
|
+
* functionAppName: 'my-flight-app',
|
|
17
|
+
* }),
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface AzureAdapterOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Azure Function App name
|
|
25
|
+
* @default 'flight-app'
|
|
26
|
+
*/
|
|
27
|
+
functionAppName?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Node.js version
|
|
30
|
+
* @default '20'
|
|
31
|
+
*/
|
|
32
|
+
nodeVersion?: '18' | '20';
|
|
33
|
+
/**
|
|
34
|
+
* Azure region
|
|
35
|
+
* @default 'eastus'
|
|
36
|
+
*/
|
|
37
|
+
region?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Authentication level
|
|
40
|
+
* @default 'anonymous'
|
|
41
|
+
*/
|
|
42
|
+
authLevel?: 'anonymous' | 'function' | 'admin';
|
|
43
|
+
/**
|
|
44
|
+
* Generate host.json
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
generateHostJson?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Generate local.settings.json for emulation
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
generateLocalSettings?: boolean;
|
|
53
|
+
}
|
|
54
|
+
declare function azureAdapter(options?: AzureAdapterOptions): FlightAdapter;
|
|
55
|
+
|
|
56
|
+
export { type AzureAdapterOptions, azureAdapter, azureAdapter as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createAdapter } from "@flightdev/core/adapters";
|
|
3
|
+
function azureAdapter(options = {}) {
|
|
4
|
+
const {
|
|
5
|
+
functionAppName = "flight-app",
|
|
6
|
+
nodeVersion = "20",
|
|
7
|
+
region = "eastus",
|
|
8
|
+
authLevel = "anonymous",
|
|
9
|
+
generateHostJson = true,
|
|
10
|
+
generateLocalSettings = true
|
|
11
|
+
} = options;
|
|
12
|
+
return createAdapter({
|
|
13
|
+
name: "@flightdev/adapter-azure",
|
|
14
|
+
async adapt(builder) {
|
|
15
|
+
const { outDir, log } = builder;
|
|
16
|
+
log.info("Generating Azure Functions deployment...");
|
|
17
|
+
const functionCode = generateAzureFunction(authLevel);
|
|
18
|
+
await builder.writeFile("src/functions/flight.ts", functionCode);
|
|
19
|
+
log.info("Created src/functions/flight.ts");
|
|
20
|
+
await builder.copy(`${outDir}/client`, "public");
|
|
21
|
+
log.info("Copied static assets to public/");
|
|
22
|
+
if (generateHostJson) {
|
|
23
|
+
const hostJson = {
|
|
24
|
+
version: "2.0",
|
|
25
|
+
logging: {
|
|
26
|
+
applicationInsights: {
|
|
27
|
+
samplingSettings: {
|
|
28
|
+
isEnabled: true,
|
|
29
|
+
excludedTypes: "Request"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
extensionBundle: {
|
|
34
|
+
id: "Microsoft.Azure.Functions.ExtensionBundle",
|
|
35
|
+
version: "[4.*, 5.0.0)"
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
await builder.writeFile("host.json", JSON.stringify(hostJson, null, 2));
|
|
39
|
+
log.info("Created host.json");
|
|
40
|
+
}
|
|
41
|
+
if (generateLocalSettings) {
|
|
42
|
+
const localSettings = {
|
|
43
|
+
IsEncrypted: false,
|
|
44
|
+
Values: {
|
|
45
|
+
AzureWebJobsStorage: "",
|
|
46
|
+
FUNCTIONS_WORKER_RUNTIME: "node",
|
|
47
|
+
AzureWebJobsFeatureFlags: "EnableWorkerIndexing"
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
await builder.writeFile("local.settings.json", JSON.stringify(localSettings, null, 2));
|
|
51
|
+
log.info("Created local.settings.json");
|
|
52
|
+
}
|
|
53
|
+
const packageJson = generateFunctionPackageJson(nodeVersion);
|
|
54
|
+
await builder.writeFile("package.json", JSON.stringify(packageJson, null, 2));
|
|
55
|
+
log.info("Created package.json");
|
|
56
|
+
const tsconfig = {
|
|
57
|
+
compilerOptions: {
|
|
58
|
+
module: "ESNext",
|
|
59
|
+
target: "ESNext",
|
|
60
|
+
moduleResolution: "Node",
|
|
61
|
+
outDir: "dist",
|
|
62
|
+
rootDir: "src",
|
|
63
|
+
strict: true,
|
|
64
|
+
esModuleInterop: true,
|
|
65
|
+
skipLibCheck: true
|
|
66
|
+
},
|
|
67
|
+
include: ["src/**/*"]
|
|
68
|
+
};
|
|
69
|
+
await builder.writeFile("tsconfig.json", JSON.stringify(tsconfig, null, 2));
|
|
70
|
+
log.info(`
|
|
71
|
+
Azure Functions adapter complete!
|
|
72
|
+
|
|
73
|
+
To run locally:
|
|
74
|
+
npm install
|
|
75
|
+
npm start
|
|
76
|
+
|
|
77
|
+
To deploy:
|
|
78
|
+
# Login to Azure
|
|
79
|
+
az login
|
|
80
|
+
|
|
81
|
+
# Create resources (first time)
|
|
82
|
+
az group create --name ${functionAppName}-rg --location ${region}
|
|
83
|
+
az storage account create --name ${functionAppName}storage --location ${region} \\
|
|
84
|
+
--resource-group ${functionAppName}-rg --sku Standard_LRS
|
|
85
|
+
az functionapp create --resource-group ${functionAppName}-rg --consumption-plan-location ${region} \\
|
|
86
|
+
--runtime node --runtime-version ${nodeVersion} --functions-version 4 \\
|
|
87
|
+
--name ${functionAppName} --storage-account ${functionAppName}storage
|
|
88
|
+
|
|
89
|
+
# Deploy
|
|
90
|
+
npm run build
|
|
91
|
+
func azure functionapp publish ${functionAppName}
|
|
92
|
+
|
|
93
|
+
Portal: https://portal.azure.com
|
|
94
|
+
`);
|
|
95
|
+
},
|
|
96
|
+
emulate: () => ({
|
|
97
|
+
env: {
|
|
98
|
+
AZURE_FUNCTIONS_ENVIRONMENT: "Development",
|
|
99
|
+
FUNCTIONS_WORKER_RUNTIME: "node"
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
supports: {
|
|
103
|
+
read: () => true,
|
|
104
|
+
streaming: () => true,
|
|
105
|
+
websockets: () => false,
|
|
106
|
+
node: () => true,
|
|
107
|
+
edge: () => false
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function generateAzureFunction(authLevel) {
|
|
112
|
+
return `/**
|
|
113
|
+
* Flight Azure Function
|
|
114
|
+
* Generated by @flightdev/adapter-azure
|
|
115
|
+
*
|
|
116
|
+
* Uses Azure Functions v4 programming model with TypeScript
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
import {
|
|
120
|
+
app,
|
|
121
|
+
HttpRequest,
|
|
122
|
+
HttpResponseInit,
|
|
123
|
+
InvocationContext,
|
|
124
|
+
} from '@azure/functions';
|
|
125
|
+
import { createReadStream, existsSync, statSync } from 'node:fs';
|
|
126
|
+
import { join, extname } from 'node:path';
|
|
127
|
+
import { Readable } from 'node:stream';
|
|
128
|
+
|
|
129
|
+
const PUBLIC_DIR = join(process.cwd(), 'public');
|
|
130
|
+
|
|
131
|
+
const MIME_TYPES: Record<string, string> = {
|
|
132
|
+
'.html': 'text/html',
|
|
133
|
+
'.js': 'text/javascript',
|
|
134
|
+
'.css': 'text/css',
|
|
135
|
+
'.json': 'application/json',
|
|
136
|
+
'.png': 'image/png',
|
|
137
|
+
'.jpg': 'image/jpeg',
|
|
138
|
+
'.svg': 'image/svg+xml',
|
|
139
|
+
'.ico': 'image/x-icon',
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
async function streamToBuffer(stream: NodeJS.ReadableStream): Promise<Buffer> {
|
|
143
|
+
const chunks: Buffer[] = [];
|
|
144
|
+
for await (const chunk of stream) {
|
|
145
|
+
chunks.push(Buffer.from(chunk));
|
|
146
|
+
}
|
|
147
|
+
return Buffer.concat(chunks);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function flightHandler(
|
|
151
|
+
request: HttpRequest,
|
|
152
|
+
context: InvocationContext
|
|
153
|
+
): Promise<HttpResponseInit> {
|
|
154
|
+
const url = new URL(request.url);
|
|
155
|
+
const pathname = url.pathname;
|
|
156
|
+
|
|
157
|
+
context.log(\`Processing request: \${request.method} \${pathname}\`);
|
|
158
|
+
|
|
159
|
+
// Health check
|
|
160
|
+
if (pathname === '/health' || pathname === '/api/health') {
|
|
161
|
+
return {
|
|
162
|
+
status: 200,
|
|
163
|
+
headers: { 'Content-Type': 'application/json' },
|
|
164
|
+
body: JSON.stringify({
|
|
165
|
+
status: 'ok',
|
|
166
|
+
azure: {
|
|
167
|
+
invocationId: context.invocationId,
|
|
168
|
+
functionName: context.functionName,
|
|
169
|
+
},
|
|
170
|
+
}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Try to serve static file
|
|
175
|
+
const staticPath = pathname.startsWith('/api')
|
|
176
|
+
? pathname.slice(4)
|
|
177
|
+
: pathname;
|
|
178
|
+
const filePath = join(PUBLIC_DIR, staticPath === '/' ? 'index.html' : staticPath);
|
|
179
|
+
|
|
180
|
+
if (filePath.startsWith(PUBLIC_DIR) && existsSync(filePath)) {
|
|
181
|
+
const stat = statSync(filePath);
|
|
182
|
+
if (!stat.isDirectory()) {
|
|
183
|
+
const ext = extname(filePath);
|
|
184
|
+
const buffer = await streamToBuffer(createReadStream(filePath));
|
|
185
|
+
return {
|
|
186
|
+
status: 200,
|
|
187
|
+
headers: {
|
|
188
|
+
'Content-Type': MIME_TYPES[ext] || 'application/octet-stream',
|
|
189
|
+
'Cache-Control': 'public, max-age=31536000, immutable',
|
|
190
|
+
},
|
|
191
|
+
body: buffer,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// SPA fallback
|
|
197
|
+
const indexPath = join(PUBLIC_DIR, 'index.html');
|
|
198
|
+
if (existsSync(indexPath)) {
|
|
199
|
+
const buffer = await streamToBuffer(createReadStream(indexPath));
|
|
200
|
+
return {
|
|
201
|
+
status: 200,
|
|
202
|
+
headers: { 'Content-Type': 'text/html' },
|
|
203
|
+
body: buffer,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
status: 404,
|
|
209
|
+
body: 'Not Found',
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Register HTTP trigger with catch-all route
|
|
214
|
+
app.http('flight', {
|
|
215
|
+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'],
|
|
216
|
+
authLevel: '${authLevel}',
|
|
217
|
+
route: '{*path}',
|
|
218
|
+
handler: flightHandler,
|
|
219
|
+
});
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
function generateFunctionPackageJson(nodeVersion) {
|
|
223
|
+
return {
|
|
224
|
+
name: "flight-azure-functions",
|
|
225
|
+
version: "1.0.0",
|
|
226
|
+
description: "Flight app deployed to Azure Functions",
|
|
227
|
+
main: "dist/functions/*.js",
|
|
228
|
+
type: "module",
|
|
229
|
+
scripts: {
|
|
230
|
+
build: "tsc",
|
|
231
|
+
watch: "tsc -w",
|
|
232
|
+
prestart: "npm run build",
|
|
233
|
+
start: "func start",
|
|
234
|
+
test: 'echo "No tests specified" && exit 0'
|
|
235
|
+
},
|
|
236
|
+
engines: {
|
|
237
|
+
node: `>=${nodeVersion}`
|
|
238
|
+
},
|
|
239
|
+
dependencies: {
|
|
240
|
+
"@azure/functions": "^4.0.0"
|
|
241
|
+
},
|
|
242
|
+
devDependencies: {
|
|
243
|
+
"@types/node": "^22.0.0",
|
|
244
|
+
"azure-functions-core-tools": "^4.0.0",
|
|
245
|
+
typescript: "^5.7.0"
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
export {
|
|
250
|
+
azureAdapter,
|
|
251
|
+
azureAdapter as default
|
|
252
|
+
};
|
|
253
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\r\n * Flight Adapter - Azure Functions\r\n * \r\n * Deploy to Azure Functions serverless platform.\r\n * Supports HTTP triggers with Node.js/TypeScript v4 programming model.\r\n * \r\n * @example\r\n * ```typescript\r\n * import { defineConfig } from '@flightdev/core';\r\n * import azure from '@flightdev/adapter-azure';\r\n * \r\n * export default defineConfig({\r\n * adapter: azure({\r\n * functionAppName: 'my-flight-app',\r\n * }),\r\n * });\r\n * ```\r\n */\r\n\r\nimport { createAdapter, type FlightAdapter, type AdapterBuilder } from '@flightdev/core/adapters';\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\nexport interface AzureAdapterOptions {\r\n /**\r\n * Azure Function App name\r\n * @default 'flight-app'\r\n */\r\n functionAppName?: string;\r\n\r\n /**\r\n * Node.js version\r\n * @default '20'\r\n */\r\n nodeVersion?: '18' | '20';\r\n\r\n /**\r\n * Azure region\r\n * @default 'eastus'\r\n */\r\n region?: string;\r\n\r\n /**\r\n * Authentication level\r\n * @default 'anonymous'\r\n */\r\n authLevel?: 'anonymous' | 'function' | 'admin';\r\n\r\n /**\r\n * Generate host.json\r\n * @default true\r\n */\r\n generateHostJson?: boolean;\r\n\r\n /**\r\n * Generate local.settings.json for emulation\r\n * @default true\r\n */\r\n generateLocalSettings?: boolean;\r\n}\r\n\r\n// ============================================================================\r\n// Adapter Implementation\r\n// ============================================================================\r\n\r\nexport default function azureAdapter(options: AzureAdapterOptions = {}): FlightAdapter {\r\n const {\r\n functionAppName = 'flight-app',\r\n nodeVersion = '20',\r\n region = 'eastus',\r\n authLevel = 'anonymous',\r\n generateHostJson = true,\r\n generateLocalSettings = true,\r\n } = options;\r\n\r\n return createAdapter({\r\n name: '@flightdev/adapter-azure',\r\n\r\n async adapt(builder: AdapterBuilder): Promise<void> {\r\n const { outDir, log } = builder;\r\n\r\n log.info('Generating Azure Functions deployment...');\r\n\r\n // Generate main function entry (v4 programming model)\r\n const functionCode = generateAzureFunction(authLevel);\r\n await builder.writeFile('src/functions/flight.ts', functionCode);\r\n log.info('Created src/functions/flight.ts');\r\n\r\n // Copy static assets\r\n await builder.copy(`${outDir}/client`, 'public');\r\n log.info('Copied static assets to public/');\r\n\r\n // Generate host.json\r\n if (generateHostJson) {\r\n const hostJson = {\r\n version: '2.0',\r\n logging: {\r\n applicationInsights: {\r\n samplingSettings: {\r\n isEnabled: true,\r\n excludedTypes: 'Request',\r\n },\r\n },\r\n },\r\n extensionBundle: {\r\n id: 'Microsoft.Azure.Functions.ExtensionBundle',\r\n version: '[4.*, 5.0.0)',\r\n },\r\n };\r\n await builder.writeFile('host.json', JSON.stringify(hostJson, null, 2));\r\n log.info('Created host.json');\r\n }\r\n\r\n // Generate local.settings.json\r\n if (generateLocalSettings) {\r\n const localSettings = {\r\n IsEncrypted: false,\r\n Values: {\r\n AzureWebJobsStorage: '',\r\n FUNCTIONS_WORKER_RUNTIME: 'node',\r\n AzureWebJobsFeatureFlags: 'EnableWorkerIndexing',\r\n },\r\n };\r\n await builder.writeFile('local.settings.json', JSON.stringify(localSettings, null, 2));\r\n log.info('Created local.settings.json');\r\n }\r\n\r\n // Generate package.json for function app\r\n const packageJson = generateFunctionPackageJson(nodeVersion);\r\n await builder.writeFile('package.json', JSON.stringify(packageJson, null, 2));\r\n log.info('Created package.json');\r\n\r\n // Generate tsconfig.json\r\n const tsconfig = {\r\n compilerOptions: {\r\n module: 'ESNext',\r\n target: 'ESNext',\r\n moduleResolution: 'Node',\r\n outDir: 'dist',\r\n rootDir: 'src',\r\n strict: true,\r\n esModuleInterop: true,\r\n skipLibCheck: true,\r\n },\r\n include: ['src/**/*'],\r\n };\r\n await builder.writeFile('tsconfig.json', JSON.stringify(tsconfig, null, 2));\r\n\r\n log.info(`\r\nAzure Functions adapter complete!\r\n\r\nTo run locally:\r\n npm install\r\n npm start\r\n\r\nTo deploy:\r\n # Login to Azure\r\n az login\r\n\r\n # Create resources (first time)\r\n az group create --name ${functionAppName}-rg --location ${region}\r\n az storage account create --name ${functionAppName}storage --location ${region} \\\\\r\n --resource-group ${functionAppName}-rg --sku Standard_LRS\r\n az functionapp create --resource-group ${functionAppName}-rg --consumption-plan-location ${region} \\\\\r\n --runtime node --runtime-version ${nodeVersion} --functions-version 4 \\\\\r\n --name ${functionAppName} --storage-account ${functionAppName}storage\r\n\r\n # Deploy\r\n npm run build\r\n func azure functionapp publish ${functionAppName}\r\n\r\nPortal: https://portal.azure.com\r\n`);\r\n },\r\n\r\n emulate: () => ({\r\n env: {\r\n AZURE_FUNCTIONS_ENVIRONMENT: 'Development',\r\n FUNCTIONS_WORKER_RUNTIME: 'node',\r\n },\r\n }),\r\n\r\n supports: {\r\n read: () => true,\r\n streaming: () => true,\r\n websockets: () => false,\r\n node: () => true,\r\n edge: () => false,\r\n },\r\n });\r\n}\r\n\r\n// ============================================================================\r\n// Code Generation\r\n// ============================================================================\r\n\r\nfunction generateAzureFunction(authLevel: string): string {\r\n return `/**\r\n * Flight Azure Function\r\n * Generated by @flightdev/adapter-azure\r\n * \r\n * Uses Azure Functions v4 programming model with TypeScript\r\n */\r\n\r\nimport {\r\n app,\r\n HttpRequest,\r\n HttpResponseInit,\r\n InvocationContext,\r\n} from '@azure/functions';\r\nimport { createReadStream, existsSync, statSync } from 'node:fs';\r\nimport { join, extname } from 'node:path';\r\nimport { Readable } from 'node:stream';\r\n\r\nconst PUBLIC_DIR = join(process.cwd(), 'public');\r\n\r\nconst MIME_TYPES: Record<string, string> = {\r\n '.html': 'text/html',\r\n '.js': 'text/javascript',\r\n '.css': 'text/css',\r\n '.json': 'application/json',\r\n '.png': 'image/png',\r\n '.jpg': 'image/jpeg',\r\n '.svg': 'image/svg+xml',\r\n '.ico': 'image/x-icon',\r\n};\r\n\r\nasync function streamToBuffer(stream: NodeJS.ReadableStream): Promise<Buffer> {\r\n const chunks: Buffer[] = [];\r\n for await (const chunk of stream) {\r\n chunks.push(Buffer.from(chunk));\r\n }\r\n return Buffer.concat(chunks);\r\n}\r\n\r\nasync function flightHandler(\r\n request: HttpRequest,\r\n context: InvocationContext\r\n): Promise<HttpResponseInit> {\r\n const url = new URL(request.url);\r\n const pathname = url.pathname;\r\n\r\n context.log(\\`Processing request: \\${request.method} \\${pathname}\\`);\r\n\r\n // Health check\r\n if (pathname === '/health' || pathname === '/api/health') {\r\n return {\r\n status: 200,\r\n headers: { 'Content-Type': 'application/json' },\r\n body: JSON.stringify({\r\n status: 'ok',\r\n azure: {\r\n invocationId: context.invocationId,\r\n functionName: context.functionName,\r\n },\r\n }),\r\n };\r\n }\r\n\r\n // Try to serve static file\r\n const staticPath = pathname.startsWith('/api') \r\n ? pathname.slice(4) \r\n : pathname;\r\n const filePath = join(PUBLIC_DIR, staticPath === '/' ? 'index.html' : staticPath);\r\n \r\n if (filePath.startsWith(PUBLIC_DIR) && existsSync(filePath)) {\r\n const stat = statSync(filePath);\r\n if (!stat.isDirectory()) {\r\n const ext = extname(filePath);\r\n const buffer = await streamToBuffer(createReadStream(filePath));\r\n return {\r\n status: 200,\r\n headers: {\r\n 'Content-Type': MIME_TYPES[ext] || 'application/octet-stream',\r\n 'Cache-Control': 'public, max-age=31536000, immutable',\r\n },\r\n body: buffer,\r\n };\r\n }\r\n }\r\n\r\n // SPA fallback\r\n const indexPath = join(PUBLIC_DIR, 'index.html');\r\n if (existsSync(indexPath)) {\r\n const buffer = await streamToBuffer(createReadStream(indexPath));\r\n return {\r\n status: 200,\r\n headers: { 'Content-Type': 'text/html' },\r\n body: buffer,\r\n };\r\n }\r\n\r\n return {\r\n status: 404,\r\n body: 'Not Found',\r\n };\r\n}\r\n\r\n// Register HTTP trigger with catch-all route\r\napp.http('flight', {\r\n methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'],\r\n authLevel: '${authLevel}',\r\n route: '{*path}',\r\n handler: flightHandler,\r\n});\r\n`;\r\n}\r\n\r\nfunction generateFunctionPackageJson(nodeVersion: string): object {\r\n return {\r\n name: 'flight-azure-functions',\r\n version: '1.0.0',\r\n description: 'Flight app deployed to Azure Functions',\r\n main: 'dist/functions/*.js',\r\n type: 'module',\r\n scripts: {\r\n build: 'tsc',\r\n watch: 'tsc -w',\r\n prestart: 'npm run build',\r\n start: 'func start',\r\n test: 'echo \\\"No tests specified\\\" && exit 0',\r\n },\r\n engines: {\r\n node: `>=${nodeVersion}`,\r\n },\r\n dependencies: {\r\n '@azure/functions': '^4.0.0',\r\n },\r\n devDependencies: {\r\n '@types/node': '^22.0.0',\r\n 'azure-functions-core-tools': '^4.0.0',\r\n typescript: '^5.7.0',\r\n },\r\n };\r\n}\r\n\r\nexport { azureAdapter };\r\n"],"mappings":";AAmBA,SAAS,qBAA8D;AAgDxD,SAAR,aAA8B,UAA+B,CAAC,GAAkB;AACnF,QAAM;AAAA,IACF,kBAAkB;AAAA,IAClB,cAAc;AAAA,IACd,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,mBAAmB;AAAA,IACnB,wBAAwB;AAAA,EAC5B,IAAI;AAEJ,SAAO,cAAc;AAAA,IACjB,MAAM;AAAA,IAEN,MAAM,MAAM,SAAwC;AAChD,YAAM,EAAE,QAAQ,IAAI,IAAI;AAExB,UAAI,KAAK,0CAA0C;AAGnD,YAAM,eAAe,sBAAsB,SAAS;AACpD,YAAM,QAAQ,UAAU,2BAA2B,YAAY;AAC/D,UAAI,KAAK,iCAAiC;AAG1C,YAAM,QAAQ,KAAK,GAAG,MAAM,WAAW,QAAQ;AAC/C,UAAI,KAAK,iCAAiC;AAG1C,UAAI,kBAAkB;AAClB,cAAM,WAAW;AAAA,UACb,SAAS;AAAA,UACT,SAAS;AAAA,YACL,qBAAqB;AAAA,cACjB,kBAAk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AO;AAAA,MACP,UAAU;AAAA,MACV,OAAO;AAAA,MACP,MAAM;AAAA,IACV;AAAA,IACA,SAAS;AAAA,MACL,MAAM,KAAK,WAAW;AAAA,IAC1B;AAAA,IACA,cAAc;AAAA,MACV,oBAAoB;AAAA,IACxB;AAAA,IACA,iBAAiB;AAAA,MACb,eAAe;AAAA,MACf,8BAA8B;AAAA,MAC9B,YAAY;AAAA,IAChB;AAAA,EACJ;AACJ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flightdev/adapter-azure",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Azure Functions adapter for Flight Framework",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"flight",
|
|
7
|
+
"adapter",
|
|
8
|
+
"azure",
|
|
9
|
+
"functions",
|
|
10
|
+
"serverless"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@flightdev/core": "0.6.7"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^22.0.0",
|
|
30
|
+
"rimraf": "^6.0.0",
|
|
31
|
+
"tsup": "^8.0.0",
|
|
32
|
+
"typescript": "^5.7.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsup --watch",
|
|
37
|
+
"clean": "rimraf dist",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
39
|
+
}
|
|
40
|
+
}
|