add more endpoint superclasses

This commit is contained in:
Erik 2022-11-09 16:18:41 +02:00
parent df2d7a7ed5
commit 0f71c25cdb
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,17 @@
const Endpoint = require('./Endpoint');
class ApiEndpoint extends Endpoint {
constructor (server, opts) {
if (!opts.path.startsWith('/')) opts.path = `/${opts.path}`;
super(server, {
...opts,
path: `/api${opts.path}`
});
}
}
module.exports = ApiEndpoint;

View File

@ -0,0 +1,18 @@
const ApiEndpoint = require("./ApiEndpoint");
class VersionedEndpoint extends ApiEndpoint {
constructor (server, opts) {
if (typeof opts.version !== 'number') throw new Error('Missing endpoint version');
if (!opts.path.startsWith('/')) opts.path = `/${opts.path}`;
super(server, {
...opts,
path: `/v${opts.version}${opts.path}`
});
}
}
module.exports = VersionedEndpoint;

View File

@ -1,4 +1,6 @@
module.exports = {
Endpoint: require('./Endpoint'),
AbstractUserDatabase: require('./AbstractUserDatabase')
AbstractUserDatabase: require('./AbstractUserDatabase'),
VersionedEndpoint: require('./VersionedEndpoint'),
ApiEndpoint: require('./ApiEndpoint'),
};