mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
Updated some types + added webapi
This commit is contained in:
parent
3bb190b53d
commit
dbbf77472c
3 changed files with 15 additions and 4 deletions
|
@ -23,7 +23,6 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/webapi": "^0.11.0",
|
"@astrojs/webapi": "^0.11.0",
|
||||||
"@vercel/node": "^1.14.0",
|
|
||||||
"esbuild": "0.14.25",
|
"esbuild": "0.14.25",
|
||||||
"globby": "^12.2.0"
|
"globby": "^12.2.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
import type { AstroIntegration, AstroConfig } from 'astro';
|
import type { AstroIntegration, AstroConfig } from 'astro';
|
||||||
import fs from 'fs/promises';
|
import type { IncomingMessage, ServerResponse } from 'http';
|
||||||
import type { PathLike } from 'fs';
|
import type { PathLike } from 'fs';
|
||||||
|
|
||||||
|
import fs from 'fs/promises';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { globby } from 'globby';
|
import { globby } from 'globby';
|
||||||
import esbuild from 'esbuild';
|
import esbuild from 'esbuild';
|
||||||
|
|
||||||
export type { VercelApiHandler, VercelRequest, VercelRequestBody, VercelRequestCookies, VercelRequestQuery, VercelResponse } from '@vercel/node';
|
export type VercelRequest = IncomingMessage;
|
||||||
|
export type VercelResponse = ServerResponse;
|
||||||
|
export type VercelHandler = (request: VercelRequest, response: VercelResponse) => void | Promise<void>;
|
||||||
|
|
||||||
const writeJson = (path: PathLike, data: any) => fs.writeFile(path, JSON.stringify(data), { encoding: 'utf-8' });
|
const writeJson = (path: PathLike, data: any) => fs.writeFile(path, JSON.stringify(data), { encoding: 'utf-8' });
|
||||||
|
|
||||||
const ENDPOINT_GLOB = 'api/**/*.{js,ts,tsx}';
|
const ENDPOINT_GLOB = 'api/**/*.{js,ts,tsx}';
|
||||||
|
|
||||||
export function vercelFunctions(): AstroIntegration {
|
function vercelFunctions(): AstroIntegration {
|
||||||
let _config: AstroConfig;
|
let _config: AstroConfig;
|
||||||
let output: URL;
|
let output: URL;
|
||||||
|
|
||||||
|
@ -59,11 +63,14 @@ export function vercelFunctions(): AstroIntegration {
|
||||||
entryPoints: endpoints.map((endpoint) => new URL(endpoint, _config.pages)).map(fileURLToPath),
|
entryPoints: endpoints.map((endpoint) => new URL(endpoint, _config.pages)).map(fileURLToPath),
|
||||||
outdir: fileURLToPath(new URL('./server/pages/api/', output)),
|
outdir: fileURLToPath(new URL('./server/pages/api/', output)),
|
||||||
outbase: fileURLToPath(new URL('./api/', _config.pages)),
|
outbase: fileURLToPath(new URL('./api/', _config.pages)),
|
||||||
|
inject: [fileURLToPath(new URL('./shims.js', import.meta.url))],
|
||||||
bundle: true,
|
bundle: true,
|
||||||
target: 'node14',
|
target: 'node14',
|
||||||
platform: 'node',
|
platform: 'node',
|
||||||
format: 'cjs',
|
format: 'cjs',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await writeJson(new URL(`./package.json`, output), { type: 'commonjs' });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
5
packages/integrations/vercel/src/shims.ts
Normal file
5
packages/integrations/vercel/src/shims.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { polyfill } from '@astrojs/webapi';
|
||||||
|
|
||||||
|
polyfill(globalThis, {
|
||||||
|
exclude: 'window document',
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue