-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
67 lines (56 loc) · 1.62 KB
/
server.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
var apiRouter = require('./api-router').router;
// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
const app = express();
// Body parser configuration
app.use(bodyParser.json());
// Template engine
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, "public")));
// Route configuration
app.get('/', (req, res) => {
res.render('index', {
subject: 'Application APIRest Node',
name: 'Page d\'accueil',
});
});
app.get('/login', (req, res) => {
res.render('login', {
subject: 'Se connecter - Application APIRest Node',
heading: 'Se connecter',
});
});
app.get('/profil', (req, res) => {
res.render('profil', {
subject: 'Profil - Application APIRest Node',
heading: 'Votre profil',
});
});
app.get('/liste-messages', (req, res) => {
res.render('messages', {
subject: 'Message - Application APIRest Node',
heading: 'Liste des messages'
});
});
app.get('/create-category', (req, res) => {
res.render('create-category', {
subject: 'Créer catégorie - Application APIRest Node',
heading: 'Création de catégorie'
});
});
app.get('/create-message', (req, res) => {
res.render('create-message', {
subject: 'Créer message - Application APIRest Node',
heading: 'Création de message'
});
});
// Utilisation du routeur API
app.use('/api/', apiRouter);
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);