basic stuff
This commit is contained in:
commit
6d36cb75ec
4 changed files with 78 additions and 0 deletions
41
index.js
Normal file
41
index.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
import express from 'express';
|
||||
import { initDb } from './db.js';
|
||||
import bodyParser from 'body-parser';
|
||||
|
||||
const app = express()
|
||||
const port = process.env.port || 5000
|
||||
|
||||
const jsonParser = bodyParser.json()
|
||||
|
||||
app.use(jsonParser);
|
||||
|
||||
app.post('/', async (req, res) => {
|
||||
var db = await initDb();
|
||||
var ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
|
||||
var { action } = req.body;
|
||||
action = action + '';
|
||||
|
||||
await db.run('DELETE FROM action WHERE addr = ? AND action = ?', [
|
||||
ip,
|
||||
action
|
||||
]);
|
||||
await db.run('INSERT INTO action (addr, action) VALUES (?, ?)', [
|
||||
ip,
|
||||
action
|
||||
]);
|
||||
let output = await db.all('SELECT * FROM action WHERE action = ?', [
|
||||
action
|
||||
])
|
||||
|
||||
console.log(`${output.length} people triggered ${action}.`);
|
||||
|
||||
res.send({
|
||||
ip,
|
||||
action,
|
||||
count: output.length
|
||||
});
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`)
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue