summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/src/middleware.ts
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2023-09-28 04:48:26 +0800
committerGravatar GitHub <noreply@github.com> 2023-09-27 16:48:26 -0400
commit4ed410db507723d8f8edd70aec508415d77ad2f5 (patch)
treedd876939fc708358d0675ba159e0a1d9af0fcd79 /packages/integrations/netlify/src/middleware.ts
parenta10a798c18512796d2c8b8ed49924dafd884e04c (diff)
downloadastro-4ed410db507723d8f8edd70aec508415d77ad2f5.tar.gz
astro-4ed410db507723d8f8edd70aec508415d77ad2f5.tar.zst
astro-4ed410db507723d8f8edd70aec508415d77ad2f5.zip
Remove Netlify adapter from core (#8574)
* New link * More explicit * Add placeholder package.json * lockfile * add keyworkds
Diffstat (limited to 'packages/integrations/netlify/src/middleware.ts')
-rw-r--r--packages/integrations/netlify/src/middleware.ts75
1 files changed, 0 insertions, 75 deletions
diff --git a/packages/integrations/netlify/src/middleware.ts b/packages/integrations/netlify/src/middleware.ts
deleted file mode 100644
index 3c2f4f697..000000000
--- a/packages/integrations/netlify/src/middleware.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-import { existsSync } from 'node:fs';
-import { join } from 'node:path';
-import { fileURLToPath, pathToFileURL } from 'node:url';
-import { ASTRO_LOCALS_HEADER } from './integration-functions.js';
-import { DENO_SHIM } from './shared.js';
-
-/**
- * It generates a Netlify edge function.
- *
- */
-export async function generateEdgeMiddleware(
- astroMiddlewareEntryPointPath: URL,
- outPath: string,
- netlifyEdgeMiddlewareHandlerPath: URL
-): Promise<URL> {
- const entryPointPathURLAsString = JSON.stringify(
- fileURLToPath(astroMiddlewareEntryPointPath).replace(/\\/g, '/')
- );
-
- const code = edgeMiddlewareTemplate(entryPointPathURLAsString, netlifyEdgeMiddlewareHandlerPath);
- const bundledFilePath = join(outPath, 'edgeMiddleware.js');
- const esbuild = await import('esbuild');
- await esbuild.build({
- stdin: {
- contents: code,
- resolveDir: process.cwd(),
- },
- target: 'es2020',
- platform: 'browser',
- outfile: bundledFilePath,
- allowOverwrite: true,
- format: 'esm',
- bundle: true,
- minify: false,
- banner: {
- js: DENO_SHIM,
- },
- });
- return pathToFileURL(bundledFilePath);
-}
-
-function edgeMiddlewareTemplate(middlewarePath: string, netlifyEdgeMiddlewareHandlerPath: URL) {
- const filePathEdgeMiddleware = fileURLToPath(netlifyEdgeMiddlewareHandlerPath);
- let handlerTemplateImport = '';
- let handlerTemplateCall = '{}';
- if (existsSync(filePathEdgeMiddleware + '.js') || existsSync(filePathEdgeMiddleware + '.ts')) {
- const stringified = JSON.stringify(filePathEdgeMiddleware.replace(/\\/g, '/'));
- handlerTemplateImport = `import handler from ${stringified}`;
- handlerTemplateCall = `handler({ request, context })`;
- } else {
- }
- return `
- ${handlerTemplateImport}
-import { onRequest } from ${middlewarePath};
-import { createContext, trySerializeLocals } from 'astro/middleware';
-export default async function middleware(request, context) {
- const url = new URL(request.url);
- const ctx = createContext({
- request,
- params: {}
- });
- ctx.locals = ${handlerTemplateCall};
- const next = async () => {
- request.headers.set(${JSON.stringify(ASTRO_LOCALS_HEADER)}, trySerializeLocals(ctx.locals));
- return await context.next();
- };
-
- return onRequest(ctx, next);
-}
-
-export const config = {
- path: "/*"
-}
-`;
-}