web-site/invite-token/app/server.js

38 lines
863 B
JavaScript
Raw Permalink Normal View History

2024-11-19 09:52:20 +00:00
import express from 'express';
export default (connection) => {
const app = new express();
app.disable('x-powered-by');
app.get(
'/',
async (req, res) => {
res.send();
},
)
app.get(
'/:id',
async (req, res) => {
console.log('called with', req.params.id)
const [[ invite ]] = await connection.query(`
SELECT token FROM invites WHERE id = '${req.params.id}'
`)
console.log(invite)
if (invite) {
console.log('sending')
res.send(invite.token);
} else {
console.log(404)
res.status(404).send(404);
}
},
)
app.use((err, req, res, next) => {
res.status(500).send('There has been a serious infernal error :(');
})
const port = process.env.PORT || 3002;
app.listen(port, () => console.log('App listening on port ' + port));
}