run-lints.ts29 lines · main
| 1 | import { NextApiRequest, NextApiResponse } from 'next' |
| 2 | |
| 3 | import { constructHeaders } from '@/lib/api/apiHelpers' |
| 4 | import apiWrapper from '@/lib/api/apiWrapper' |
| 5 | import { DEFAULT_EXPOSED_SCHEMAS } from '@/lib/api/self-hosted/constants' |
| 6 | import { getLints } from '@/lib/api/self-hosted/lints' |
| 7 | |
| 8 | export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler) |
| 9 | |
| 10 | async function handler(req: NextApiRequest, res: NextApiResponse) { |
| 11 | const { method } = req |
| 12 | |
| 13 | switch (method) { |
| 14 | case 'GET': |
| 15 | const { data, error } = await getLints({ |
| 16 | headers: constructHeaders(req.headers), |
| 17 | exposedSchemas: DEFAULT_EXPOSED_SCHEMAS, |
| 18 | }) |
| 19 | |
| 20 | if (error) { |
| 21 | return res.status(400).json(error) |
| 22 | } else { |
| 23 | return res.status(200).json(data) |
| 24 | } |
| 25 | default: |
| 26 | res.setHeader('Allow', ['GET']) |
| 27 | res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } }) |
| 28 | } |
| 29 | } |