umami/lib/response.js

34 lines
771 B
JavaScript
Raw Normal View History

export function ok(res, data = {}) {
return res.status(200).json(data);
}
export function redirect(res, url) {
res.setHeader('Location', url);
return res.status(303).end();
}
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-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-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-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-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);
}