mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 12:57:46 +00:00
This PR adds an optional property called `sort` to each framework so that we can change the order returned in the API. The reason this is necessary is because the order of the original array determines the precedence of framework detection. So we need another way to indicate the order of templates/examples returned from the API. In particular, we need "Next.js" to be first and "Other" to be last. I also updated the deprecated `@now/node` usage to `@vercel/node` in the API.
36 lines
972 B
TypeScript
36 lines
972 B
TypeScript
import { NowRequest, NowResponse } from '@vercel/node';
|
|
import { withApiHandler } from './_lib/util/with-api-handler';
|
|
import _frameworks, { Framework } from '../packages/frameworks';
|
|
|
|
const frameworks = (_frameworks as Framework[])
|
|
.sort(
|
|
(a, b) =>
|
|
(a.sort || Number.MAX_SAFE_INTEGER) - (b.sort || Number.MAX_SAFE_INTEGER)
|
|
)
|
|
.map(frameworkItem => {
|
|
const framework = {
|
|
...frameworkItem,
|
|
detectors: undefined,
|
|
sort: undefined,
|
|
};
|
|
|
|
if (framework.logo) {
|
|
framework.logo = `https://res.cloudinary.com/zeit-inc/image/fetch/${framework.logo}`;
|
|
}
|
|
|
|
return framework;
|
|
});
|
|
|
|
export default withApiHandler(async function (
|
|
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'
|
|
);
|
|
return res.status(200).json(frameworks);
|
|
});
|