endpoint 404

This commit is contained in:
Erik 2022-11-24 00:07:06 +02:00
parent f4a04bc67b
commit b50f603ee2
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 31 additions and 4 deletions

View File

@ -0,0 +1,27 @@
const { ApiEndpoint } = require("../../interfaces");
// Just so requests to /api/.. don't get sent the index.html file on invalid path
// Could've also just defined this quick and dirty in the Server class,
// but I feel this is better for readability
class Api404 extends ApiEndpoint {
constructor (server) {
super(server, {
name: 'api404',
path: '/*'
});
this.methods = [
[ 'get', this.get.bind(this) ]
];
}
async get (req, res) {
res.status(404).end();
}
}
module.exports = Api404;

View File

@ -18,7 +18,7 @@ class LogoutEndpoint extends ApiEndpoint {
logout (req, res) {
req.session.destroy();
res.clearCookie(this.server.authenticator.cookieName);
res.clearCookie(this.server.auth.cookieName);
res.end();
}

View File

@ -22,7 +22,7 @@ class UsersEndpoint extends ApiEndpoint {
const { amount, page } = query;
if (!page) return res.status(400).send('Missing page number');
const users = await this.server.users.fetchUsers(page, amount);
res.json(users.map(user => user.json));
res.json(users.map(user => user.safeJson));
}
async user (req, res) {
@ -30,7 +30,7 @@ class UsersEndpoint extends ApiEndpoint {
const { userid } = params;
const user = await this.server.users.fetchUser(userid);
if (!user) return res.status(404).end();
res.json(user);
res.json(user.safeJson);
}
async userApplications (req, res) {
@ -39,7 +39,7 @@ class UsersEndpoint extends ApiEndpoint {
const user = await this.server.users.fetchUser(userid);
if (!user) return res.status(404).send('Could not find the user');
const applications = await user.fetchApplications();
res.json(Object.values(applications).map(app => app.json));
res.json(Object.values(applications).map(app => app.safeJson));
}
}