const express = require('express');
const hbs = require('hbs');
const fs = require('fs');

const port = process.env.PORT || 3000; 

var app = express();

hbs.registerPartials(__dirname + '/views/partials');
app.set('view engine', 'hbs');


app.use( (req,res,next) => {
    var now = new Date().toString();
    var log = `${now}: ${req.method} ${req.url}`;
    console.log(log);
    fs.appendFile('server.log',log + '\n', (err) => {
        if(err){
            console.log('Unable to write to the file');
        }
    });
    next();
})

app.use((req,res,next) => {
    res.render('maintenance.hbs');
});

app.use( express.static(__dirname + '/public'));

hbs.registerHelper('getCurrentYear', () => {
   return new Date().getFullYear();
});

hbs.registerHelper('screamIt', (text) => {
    return text.toUpperCase();
})
app.get('/', (req, res) => {
    // res.send('<h1>Hello Express!</h1>');
    res.render('home.hbs', {
        pageTitle: 'home Page',
        welcomeMessage: 'Welcome bitch!',
    });
});

app.get('/about', (req, res) => {
res.render('about.hbs', {
    pageTitle: 'About Page',
});
});

app.get('/bad', (req, res) => {
    res.send({
        error: 'Bad Request'
    });
    });
app.listen(port, () => {
    console.log(`Server is up on port ${port}`);
});
@@ -532,16 +532,19 @@
 ();%0A%7D)%0A%0A
+// 
 app.use(
@@ -559,28 +559,31 @@
 ,next) =%3E %7B%0A
+//
     
+ 
 res.render('
@@ -601,16 +601,19 @@
 .hbs');%0A
+// 
 %7D);%0A%0Aapp

remove maintenance mode