mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 12:57:46 +00:00
* Add API for frameworks and examples * Adjust headers * Update frameworks list * Always use latest * Add types * Use now repo for downloading and listing * Use .existsSync * Remove unused packages * Use 307 for redirect * Add examples * Update tsconfig.json Co-Authored-By: Steven <steven@ceriously.com> * Make examples unique * Remove detectors from frameworks API * Use /api instead of Next.js * Install dependencies * Rename project * Change name * Empty * Change name * Update api/tsconfig.json Co-Authored-By: Steven <steven@ceriously.com> * Update examples Co-authored-by: Steven <steven@ceriously.com>
30 lines
795 B
TypeScript
30 lines
795 B
TypeScript
import { NowRequest, NowResponse } from '@now/node';
|
|
|
|
type Handler = (req: NowRequest, res: NowResponse) => Promise<any>;
|
|
|
|
export function withApiHandler(handler: Handler): Handler {
|
|
return async (req: NowRequest, res: NowResponse) => {
|
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET');
|
|
res.setHeader(
|
|
'Access-Control-Allow-Headers',
|
|
'Authorization, Accept, Content-Type'
|
|
);
|
|
|
|
if (req.method === 'OPTIONS') {
|
|
return res.status(200).json({});
|
|
}
|
|
|
|
if (req.method !== 'GET') {
|
|
return res.status(404).json({
|
|
error: {
|
|
code: 'not_found',
|
|
message: 'Only GET requests are supported for this endpoint.',
|
|
},
|
|
});
|
|
}
|
|
|
|
return handler(req, res);
|
|
};
|
|
}
|