const express = require('express');
const path = require('path');

const app = express();
app.use(express.urlencoded());
const port = 3001;

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, '/index.html'));
});

app.post('/', (req, res) => {
    const body = req.body;
    const beerCount = parseInt(body.beerCount);
    if(isNaN(beerCount)) {
        console.log("NOOOO PANIC PANIC!!!!! WE NEVER ANTICIPATED SUCH AN ANSWER AJPIFGNLDFG");
        console.log("Also here is a cool flag :) IGCTF-KLARRIO{brand_brand_paniek_paniek_brand}");
        res.send('Something went horribly wrong... Check logs. Bailing out!');
        process.exit(1);
    } else {
        res.send('It works :)');
    }
});

app.listen(port, () => {
    console.log(`Express app listening on port ${port}. Any logs performed by POST requests land here...`);
});