added invite-token app
This commit is contained in:
parent
9a19de8c4a
commit
40ae646b0b
|
@ -0,0 +1 @@
|
|||
node-modules
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
|
@ -0,0 +1,8 @@
|
|||
# FROM node:latest
|
||||
FROM alpine as SOURCE
|
||||
RUN apk add --update nodejs npm
|
||||
COPY package.json /app/package.json
|
||||
WORKDIR /app
|
||||
RUN npm install
|
||||
COPY . /app
|
||||
ENTRYPOINT ["node", "index.js"]
|
|
@ -0,0 +1 @@
|
|||
docker build . -t invite-token
|
|
@ -0,0 +1,16 @@
|
|||
import mysql from 'mysql2/promise';
|
||||
|
||||
export default () =>
|
||||
mysql.createPool({
|
||||
host : process.env.MYSQL_HOST,
|
||||
user : process.env.MYSQL_USER,
|
||||
password : process.env.MYSQL_PASSWORD,
|
||||
database : process.env.MYSQL_DATABASE,
|
||||
waitForConnections: true,
|
||||
connectionLimit: 100,
|
||||
maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`
|
||||
idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000
|
||||
queueLimit: 0,
|
||||
enableKeepAlive: true,
|
||||
keepAliveInitialDelay: 0,
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
import "dotenv/config";
|
||||
import database from './database.js';
|
||||
import server from './server.js';
|
||||
|
||||
server(
|
||||
database(),
|
||||
);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "invite-token",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "nodemon node index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Giles Bradshaw <giles.bradshaw@sigyl.com> (https://sigyl.com/)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^5.0.0-beta.1",
|
||||
"mysql2": "^3.9.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
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));
|
||||
}
|
Loading…
Reference in New Issue