endpoint 404
This commit is contained in:
parent
f4a04bc67b
commit
b50f603ee2
27
src/server/endpoints/api/Api404.js
Normal file
27
src/server/endpoints/api/Api404.js
Normal 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;
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user