add loc.sh routes and systems
parent
44d44ec043
commit
df3ae0d3f2
|
@ -0,0 +1,6 @@
|
|||
import { Server, ServerManagement } from '../../class';
|
||||
|
||||
export default function (management: ServerManagement) {
|
||||
const server = new Server(management, 3890, `${__dirname}/routes`);
|
||||
return server;
|
||||
}
|
|
@ -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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
Loading…
Reference in New Issue