-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (37 loc) · 997 Bytes
/
app.js
File metadata and controls
43 lines (37 loc) · 997 Bytes
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
import express from 'express'
import pug from 'pug'
import favicon from 'serve-favicon'
import sassMiddleware from 'node-sass-middleware'
import routes from './src/app/routes'
const env = 'production',
port = process.env.PORT || 3000,
publicDir = `${__dirname}/public`,
viewDir = `${__dirname}/src/views`,
faviconDir = `${__dirname}/public/img/favicon.png`,
app = express()
app
.set( 'views', viewDir )
.set( 'view engine', 'pug' )
.set( 'port', port )
.set( 'env', env )
.use(sassMiddleware({
src: `${__dirname}/src/scss`,
dest: publicDir,
debug: false,
outputStyle: 'compressed'
}))
.use( express.static(publicDir) )
.use( favicon(faviconDir) )
.use( routes )
if ( app.get('env') === 'production' ) {
app.use((req, res, next) => {
let err = new Error('Not Found')
err.status = 404
next(err)
})
app.use((err, req, res, next) => {
res.status(err.status || 500)
res.render('error', { err: err })
})
}
export default app