2020-08-08 02:19:42 +02:00
|
|
|
export function ok(res, data = {}) {
|
2022-03-11 05:39:11 +01:00
|
|
|
return json(res, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function json(res, data = {}) {
|
2020-08-08 02:19:42 +02:00
|
|
|
return res.status(200).json(data);
|
|
|
|
}
|
|
|
|
|
2022-03-19 05:57:58 +01:00
|
|
|
export function send(res, data, type = 'text/plain') {
|
2022-03-19 05:24:46 +01:00
|
|
|
res.setHeader('Content-Type', type);
|
|
|
|
|
|
|
|
return res.status(200).send(data);
|
2022-03-11 05:39:11 +01:00
|
|
|
}
|
|
|
|
|
2020-08-08 02:19:42 +02:00
|
|
|
export function redirect(res, url) {
|
2022-03-19 05:24:46 +01:00
|
|
|
res.setHeader('Location', url);
|
|
|
|
|
|
|
|
return res.status(303).end();
|
2020-08-08 02:19:42 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 10:17:15 +02:00
|
|
|
export function badRequest(res, msg = '400 Bad Request') {
|
2020-08-09 11:03:37 +02:00
|
|
|
return res.status(400).end(msg);
|
2020-08-08 02:19:42 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 10:17:15 +02:00
|
|
|
export function unauthorized(res, msg = '401 Unauthorized') {
|
2020-08-09 11:03:37 +02:00
|
|
|
return res.status(401).end(msg);
|
2020-08-08 02:19:42 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 10:17:15 +02:00
|
|
|
export function forbidden(res, msg = '403 Forbidden') {
|
2020-08-09 11:03:37 +02:00
|
|
|
return res.status(403).end(msg);
|
2020-08-08 02:19:42 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 10:17:15 +02:00
|
|
|
export function notFound(res, msg = '404 Not Found') {
|
|
|
|
return res.status(404).end(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function methodNotAllowed(res, msg = '405 Method Not Allowed') {
|
2020-08-09 11:03:37 +02:00
|
|
|
res.status(405).end(msg);
|
2020-08-08 02:19:42 +02:00
|
|
|
}
|
2020-08-12 05:05:40 +02:00
|
|
|
|
2020-08-15 10:17:15 +02:00
|
|
|
export function serverError(res, msg = '500 Internal Server Error') {
|
2020-08-12 05:05:40 +02:00
|
|
|
res.status(500).end(msg);
|
|
|
|
}
|