forked from bcalou/tp-quiprendquoi-front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (31 loc) · 998 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const express = require('express');
const dotenv = require('dotenv').config();
const bodyParser = require('body-parser');
const axios = require('axios');
const app = express();
app.set('view engine', 'pug');
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', function(req, res) {
res.render('index', { title: 'Qui prend quoi ?' });
});
app.post('/party', (req, res) => {
axios
.post(`${process.env.API_URL}/party`, req.body)
.then(({ data }) => res.redirect(`/party/${data._id}`))
.catch((err) => res.send(err));
});
app.get('/party/:id', (req, res) => {
axios
.get(`${process.env.API_URL}/party/${req.params.id}`)
.then(({ data }) =>
res.render('party', {
party: data,
title: data.name,
url: `${process.env.FRONT_URL}:${process.env.PORT}/party/${data._id}`,
}),
)
.catch((err) => console.log(err));
});
app.listen(process.env.PORT, () =>
console.log(`Front app listening on port ${process.env.PORT}!`),
);