11const express = require ( 'express' ) ,
22 exphbs = require ( 'express-handlebars' ) ,
3+ fs = require ( 'fs' ) ,
34 path = require ( 'path' ) ,
45 favicon = require ( 'serve-favicon' ) ,
5- logger = require ( 'morgan' ) ,
6+ morgan = require ( 'morgan' ) ,
67 cookieParser = require ( 'cookie-parser' ) ,
7- bodyParser = require ( 'body-parser' ) ,
88 Handlebars = require ( 'handlebars' ) ,
99 { allowInsecurePrototypeAccess } = require ( '@handlebars/allow-prototype-access' ) ,
1010
@@ -27,11 +27,13 @@ app.engine('hbs', hbs.engine);
2727app . set ( 'view engine' , 'hbs' ) ;
2828app . set ( 'views' , path . join ( __dirname , 'views' ) ) ;
2929
30+ // create a write stream (in append mode)
31+ const accessLogStream = fs . createWriteStream ( path . join ( __dirname , '/logs/access.log' ) , { flags : 'a' } ) ;
32+ app . use ( morgan ( 'combined' , { stream : accessLogStream } ) ) ;
3033
3134app . use ( favicon ( __dirname + '/public/images/favicon.ico' ) ) ;
32- app . use ( logger ( 'dev' ) ) ;
33- app . use ( bodyParser . json ( ) ) ;
34- app . use ( bodyParser . urlencoded ( { extended : false } ) ) ;
35+ app . use ( express . json ( ) ) ;
36+ app . use ( express . urlencoded ( { extended : true } ) ) ;
3537app . use ( cookieParser ( ) ) ;
3638app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
3739
0 commit comments