add loc.sh routes and systems

merge-requests/11/merge
Matthew 2020-05-05 19:12:44 -04:00
parent 98c73ca2e9
commit 4d6af1ea5f
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
3 changed files with 29 additions and 0 deletions

6
src/api/loc.sh/main.ts Normal file
View File

@ -0,0 +1,6 @@
import { Server, ServerManagement } from '../../class';
export default function (management: ServerManagement) {
const server = new Server(management, 3890, `${__dirname}/routes`);
return server;
}

View File

@ -0,0 +1,22 @@
import { Route, Server } from '../../../class';
import { RedirectInterface } from '../../../models';
export default class Root extends Route {
constructor(server: Server) {
super(server, { path: '/' });
}
public bind() {
this.router.get('/:key', async (req, res) => {
try {
// @ts-ignore
const link: RedirectInterface = await this.server.client.db.redirect.findOne({ key: req.params.key }).lean().exec();
if (!link) return res.status(404).json({ code: this.constants.codes.NOT_FOUND, message: this.constants.messages.NOT_FOUND });
return res.redirect(link.to);
} catch (err) {
this.server.client.util.handleError(err);
return res.status(500).json({ code: this.constants.codes.SERVER_ERROR, message: this.constants.messages.SERVER_ERROR });
}
});
}
}

1
src/api/server.ts Normal file
View File

@ -0,0 +1 @@