refactor(api): cors duplication (#109)
* refactor(api): cors duplication * refactor(middleware): moved content-type setter to top
This commit is contained in:
parent
1b78ffaa91
commit
7eff77ccc4
1 changed files with 5 additions and 20 deletions
|
@ -48,12 +48,11 @@ export type NextApiRes = NextApiResponse & {
|
|||
// }
|
||||
|
||||
export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse) => unknown) => (req: NextApiReq, res: NextApiRes) => {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Content-Allow-Methods', 'GET,HEAD,POST,OPTIONS');
|
||||
res.setHeader('Access-Control-Max-Age', '86400');
|
||||
res.error = (message: string) => {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Content-Allow-Methods', 'GET,HEAD,POST,OPTIONS');
|
||||
res.setHeader('Access-Control-Max-Age', '86400');
|
||||
|
||||
res.json({
|
||||
error: message,
|
||||
});
|
||||
|
@ -61,10 +60,6 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
|
|||
|
||||
res.forbid = (message: string) => {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Content-Allow-Methods', 'GET,HEAD,POST,OPTIONS');
|
||||
res.setHeader('Access-Control-Max-Age', '86400');
|
||||
|
||||
res.status(403);
|
||||
res.json({
|
||||
error: '403: ' + message,
|
||||
|
@ -72,11 +67,6 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
|
|||
};
|
||||
|
||||
res.bad = (message: string) => {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Content-Allow-Methods', 'GET,HEAD,POST,OPTIONS');
|
||||
res.setHeader('Access-Control-Max-Age', '86400');
|
||||
|
||||
res.status(401);
|
||||
res.json({
|
||||
error: '403: ' + message,
|
||||
|
@ -84,11 +74,6 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
|
|||
};
|
||||
|
||||
res.json = (json: any) => {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Content-Allow-Methods', 'GET,HEAD,POST,OPTIONS');
|
||||
res.setHeader('Access-Control-Max-Age', '86400');
|
||||
|
||||
res.end(JSON.stringify(json));
|
||||
};
|
||||
|
||||
|
@ -158,4 +143,4 @@ export const setCookie = (
|
|||
const signed = sign64(String(value), config.core.secret);
|
||||
|
||||
res.setHeader('Set-Cookie', serialize(name, signed, options));
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue