{"size": 1290, "ext": "js", "max_stars_repo_path": "src/app.js", "max_stars_repo_name": "MoustaphaMariam/node-chat", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/app.js", "max_issues_repo_name": "MoustaphaMariam/node-chat", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/app.js", "max_forks_repo_name": "MoustaphaMariam/node-chat", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.4545454545, "max_line_length": 89, "alphanum_fraction": 0.6550387597}
const express = require('express');
const morgan = require('morgan');
const helmet = require('helmet');
const http = require('http');

const app = express();

const server = http.createServer(app);
const io = require('socket.io')(server);

const PORT = process.env.PORT || 1337;


/**
 * Configuration du moteur de template
 */

app.set('view engine', 'pug');
app.set('views', './src/views');

app.locals.pretty = true; // Utile si on veut debugguer le code HTML généré côté client

require('./chat-serveur')(io);

/**
 * Middlewares (fonctions intermediaires) de l'application Express
 */

app.use(helmet());
app.use(morgan('tiny'));
app.use(express.static('./src/static'));

/**
 * Routes de l'application Express
 */

app.get('/', (req, res) => {
    res.render('index');
});

// Route qui va écouter sur http://localhost:1337/chat
app.get('/chat', (req, res) => {
    // Un paramètre pseudo est obligatoire pour accéder à cette route:
    if (!req.query.pseudo) {
        return res.redirect('/'); // Redirige vers la page de login
    }

    const pseudo = req.query.pseudo;
    
    res.render('chat', { pseudo });
});


// L'application Express va écouter et répondre sur le port réseau n°1337
server.listen(PORT, () => console.log('Le serveur écoute sur http://localhost:' + PORT));