This repository has been archived on 2021-05-27. You can view files and clone it, but cannot push or open issues or pull requests.
Files
ReRedirector/src/app.ts

25 lines
531 B
TypeScript

import express from 'express';
import morgan from "morgan";
import { getLocationOfTarget } from './app.service';
const port = Number(process.env.PORT) || 3000;
const app = express();
app.use(morgan('common'))
app.get('/*', async (req, res) => {
const target = req.url.slice(1);
const location = await getLocationOfTarget(target);
if (location) {
res.redirect(location);
}
else {
res.sendStatus(404);
}
});
app.listen(port, () => {
console.log(`Now listening on port ${port}!`);
});