forked from HarryWho/codedamn.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
40 lines (33 loc) · 1.05 KB
/
index.ts
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
import * as express from 'express'
import * as bodyParser from 'body-parser'
import * as path from 'path'
import * as exphbs from 'express-handlebars'
import routes from './controllers'
import * as helmet from 'helmet'
import * as xdebug from 'debug'
import * as mongoose from 'mongoose'
const app = express()
const debug = xdebug('cd:index')
mongoose.connect('mongodb://localhost/codedamn')
if(process.env.NODE_ENV != 'production') { // not in production. Need express to serve static files
app.use('/assets', express.static(path.join(__dirname, 'assets')))
} else {
// set up debug variables
process.env.DEBUG = "cd:*"
process.env.DEBUG_COLORS = 'true'
}
// nginx is configured for static assets
app.engine('.hbs', exphbs({
extname: '.hbs',
helpers: {
inc: function(value, options) {
return parseInt(value) + 1;
}
}
}))
app.set('view engine', '.hbs')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
routes(app) // register route
app.use(helmet())
app.listen(1337, () => debug('Server up and running at localhost:1337'))