feat: init

This commit is contained in:
2026-02-13 22:02:30 +01:00
commit 8f9ff830fb
16711 changed files with 3307340 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
export type { AzureOptions as PresetOptions } from "./types";
declare const _default: readonly [any, any];
export default _default;

44
node_modules/nitropack/dist/presets/azure/preset.mjs generated vendored Normal file
View File

@@ -0,0 +1,44 @@
import { defineNitroPreset } from "nitropack/kit";
import { writeFunctionsRoutes, writeSWARoutes } from "./utils.mjs";
const azure = defineNitroPreset(
{
entry: "./runtime/azure-swa",
output: {
serverDir: "{{ output.dir }}/server/functions",
publicDir: "{{ output.dir }}/public/{{ baseURL }}"
},
commands: {
preview: "npx @azure/static-web-apps-cli start {{ output.publicDir }} --api-location {{ output.serverDir }}"
},
hooks: {
async compiled(ctx) {
await writeSWARoutes(ctx);
}
}
},
{
name: "azure-swa",
aliases: ["azure"],
stdName: "azure_static",
url: import.meta.url
}
);
const azureFunctions = defineNitroPreset(
{
serveStatic: true,
entry: "./runtime/azure-functions",
commands: {
deploy: "az functionapp deployment source config-zip -g <resource-group> -n <app-name> --src {{ output.dir }}/deploy.zip"
},
hooks: {
async compiled(ctx) {
await writeFunctionsRoutes(ctx);
}
}
},
{
name: "azure-functions",
url: import.meta.url
}
);
export default [azure, azureFunctions];

View File

@@ -0,0 +1,5 @@
import "#nitro-internal-pollyfills";
import type { HttpRequest, HttpResponse } from "@azure/functions";
export declare function handle(context: {
res: HttpResponse;
}, req: HttpRequest): Promise<void>;

View File

@@ -0,0 +1,24 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitropack/runtime";
import {
getAzureParsedCookiesFromHeaders,
normalizeLambdaOutgoingHeaders
} from "nitropack/runtime/internal";
const nitroApp = useNitroApp();
export async function handle(context, req) {
const url = "/" + (req.params.url || "");
const { body, status, statusText, headers } = await nitroApp.localCall({
url,
headers: req.headers,
method: req.method || void 0,
// https://github.com/Azure/azure-functions-host/issues/293
body: req.rawBody
});
context.res = {
status,
// cookies https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=typescript%2Cwindows%2Cazure-cli&pivots=nodejs-model-v4#http-response
cookies: getAzureParsedCookiesFromHeaders(headers),
headers: normalizeLambdaOutgoingHeaders(headers, true),
body: body ?? statusText
};
}

View File

@@ -0,0 +1,5 @@
import "#nitro-internal-pollyfills";
import type { HttpRequest, HttpResponse } from "@azure/functions";
export declare function handle(context: {
res: HttpResponse;
}, req: HttpRequest): Promise<void>;

View File

@@ -0,0 +1,31 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitropack/runtime";
import {
getAzureParsedCookiesFromHeaders,
normalizeLambdaOutgoingHeaders
} from "nitropack/runtime/internal";
import { parseURL } from "ufo";
const nitroApp = useNitroApp();
export async function handle(context, req) {
let url;
if (req.headers["x-ms-original-url"]) {
const parsedURL = parseURL(req.headers["x-ms-original-url"]);
url = parsedURL.pathname + parsedURL.search;
} else {
url = "/api/" + (req.params.url || "");
}
const { body, status, headers } = await nitroApp.localCall({
url,
headers: req.headers,
method: req.method || void 0,
// https://github.com/Azure/azure-functions-nodejs-worker/issues/294
// https://github.com/Azure/azure-functions-host/issues/293
body: req.bufferBody ?? req.rawBody
});
context.res = {
status,
cookies: getAzureParsedCookiesFromHeaders(headers),
headers: normalizeLambdaOutgoingHeaders(headers, true),
body
};
}

13
node_modules/nitropack/dist/presets/azure/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
export interface AzureOptions {
config?: {
platform?: {
apiRuntime?: string;
[key: string]: unknown;
};
navigationFallback?: {
rewrite?: string;
[key: string]: unknown;
};
[key: string]: unknown;
};
}

0
node_modules/nitropack/dist/presets/azure/types.mjs generated vendored Normal file
View File

3
node_modules/nitropack/dist/presets/azure/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
import type { Nitro } from "nitropack/types";
export declare function writeFunctionsRoutes(nitro: Nitro): Promise<void>;
export declare function writeSWARoutes(nitro: Nitro): Promise<void>;

183
node_modules/nitropack/dist/presets/azure/utils.mjs generated vendored Normal file
View File

@@ -0,0 +1,183 @@
import { createWriteStream } from "node:fs";
import fsp from "node:fs/promises";
import archiver from "archiver";
import { writeFile } from "nitropack/kit";
import { join, resolve } from "pathe";
export async function writeFunctionsRoutes(nitro) {
const host = {
version: "2.0",
extensions: { http: { routePrefix: "" } }
};
const functionDefinition = {
entryPoint: "handle",
bindings: [
{
authLevel: "anonymous",
type: "httpTrigger",
direction: "in",
name: "req",
route: "{*url}",
methods: ["delete", "get", "head", "options", "patch", "post", "put"]
},
{
type: "http",
direction: "out",
name: "res"
}
]
};
await writeFile(
resolve(nitro.options.output.serverDir, "function.json"),
JSON.stringify(functionDefinition)
);
await writeFile(
resolve(nitro.options.output.dir, "host.json"),
JSON.stringify(host)
);
await _zipDirectory(
nitro.options.output.dir,
join(nitro.options.output.dir, "deploy.zip")
);
}
export async function writeSWARoutes(nitro) {
const host = {
version: "2.0"
};
const supportedNodeVersions = /* @__PURE__ */ new Set(["16", "18", "20"]);
let nodeVersion = "18";
try {
const currentNodeVersion = JSON.parse(
await fsp.readFile(join(nitro.options.rootDir, "package.json"), "utf8")
).engines.node;
if (supportedNodeVersions.has(currentNodeVersion)) {
nodeVersion = currentNodeVersion;
}
} catch {
const currentNodeVersion = process.versions.node.slice(0, 2);
if (supportedNodeVersions.has(currentNodeVersion)) {
nodeVersion = currentNodeVersion;
}
}
const config = {
...nitro.options.azure?.config,
// Overwrite routes for now, we will add existing routes after generating routes
routes: [],
platform: {
apiRuntime: `node:${nodeVersion}`,
...nitro.options.azure?.config?.platform
},
navigationFallback: {
rewrite: "/api/server",
...nitro.options.azure?.config?.navigationFallback
}
};
const routeFiles = nitro._prerenderedRoutes || [];
const indexFileExists = routeFiles.some(
(route) => route.fileName === "/index.html"
);
if (!indexFileExists) {
config.routes.unshift(
{
route: "/index.html",
redirect: "/"
},
{
route: "/",
rewrite: "/api/server"
}
);
}
const suffix = "/index.html".length;
for (const { fileName } of routeFiles) {
if (!fileName || !fileName.endsWith("/index.html")) {
continue;
}
config.routes.unshift({
route: fileName.slice(0, -suffix) || "/",
rewrite: fileName
});
}
for (const { fileName } of routeFiles) {
if (!fileName || !fileName.endsWith(".html") || fileName.endsWith("index.html")) {
continue;
}
const route = fileName.slice(0, -".html".length);
const existingRouteIndex = config.routes.findIndex(
(_route) => _route.route === route
);
if (existingRouteIndex !== -1) {
config.routes.splice(existingRouteIndex, 1);
}
config.routes.unshift({
route,
rewrite: fileName
});
}
if (nitro.options.azure?.config && "routes" in nitro.options.azure.config && Array.isArray(nitro.options.azure.config.routes)) {
for (const customRoute of nitro.options.azure.config.routes.reverse()) {
const existingRouteMatchIndex = config.routes.findIndex(
(value) => value.route === customRoute.route
);
if (existingRouteMatchIndex === -1) {
config.routes.unshift(customRoute);
} else {
config.routes[existingRouteMatchIndex] = customRoute;
}
}
}
const functionDefinition = {
entryPoint: "handle",
bindings: [
{
authLevel: "anonymous",
type: "httpTrigger",
direction: "in",
name: "req",
route: "{*url}",
methods: ["delete", "get", "head", "options", "patch", "post", "put"]
},
{
type: "http",
direction: "out",
name: "res"
}
]
};
await writeFile(
resolve(nitro.options.output.serverDir, "function.json"),
JSON.stringify(functionDefinition, null, 2)
);
await writeFile(
resolve(nitro.options.output.serverDir, "../host.json"),
JSON.stringify(host, null, 2)
);
const stubPackageJson = resolve(
nitro.options.output.serverDir,
"../package.json"
);
await writeFile(stubPackageJson, JSON.stringify({ private: true }));
await writeFile(
resolve(nitro.options.rootDir, "staticwebapp.config.json"),
JSON.stringify(config, null, 2)
);
if (!indexFileExists) {
const baseURLSegments = nitro.options.baseURL.split("/").filter(Boolean);
const relativePrefix = baseURLSegments.map(() => "..").join("/");
await writeFile(
resolve(
nitro.options.output.publicDir,
relativePrefix ? `${relativePrefix}/index.html` : "index.html"
),
""
);
}
}
function _zipDirectory(dir, outfile) {
const archive = archiver("zip", { zlib: { level: 9 } });
const stream = createWriteStream(outfile);
return new Promise((resolve2, reject) => {
archive.glob("**/*", { cwd: dir, nodir: true, dot: true, follow: true }).on("error", (err) => reject(err)).pipe(stream);
stream.on("close", () => resolve2(void 0));
archive.finalize();
});
}