-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (32 loc) · 880 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
37
38
39
40
41
42
const express = require( 'express' )
const ENV = require( 'dotenv' ).config().parsed
const bodyParser = require( 'body-parser' )
const app = express()
const fs = require( 'fs' )
const PORT = ENV.NODE_ENV === 'production' ? ENV.PORT : ENV.DEV_PORT
app.set( 'views', './views' )
app.set( 'view engine', 'ejs' )
app.use( express.static( 'public' ) )
app.use( express.static( 'views' ) )
app.use( bodyParser.urlencoded( {
extended: false
} ) )
app.use( bodyParser.json() )
app.get( '*', ( req, res, next ) => {
const CSS_FILE = './public/styles/critical.css'
fs.readFile( CSS_FILE, 'utf8', ( err,data ) => {
if ( err ) {
return console.log( err )
}
if ( data ) {
app.locals.criticalCSS = data
}
next()
} )
} )
app.get( '/', ( req, res ) => {
res.render( 'index' )
} )
app.listen( PORT, () => {
console.log( `Hello from http://localhost:${ PORT }` )
} )