forked from amiuhle/iot-kickerboard
/
server.js
50 lines (40 loc) · 1.14 KB
/
server.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
43
44
45
46
47
48
49
50
import 'babel-polyfill'
import bodyParser from 'body-parser'
// Fast, unopinionated, minimalist web framework for Node.js
// https://expressjs.com/en/4x/api.html
import express from 'express'
// Minimal Templating on Steroids
// http://handlebarsjs.com/
import exphbs from 'express-handlebars'
import logger from 'morgan'
// import our routes
import {
api,
pages
} from './routes'
// create express application
const app = express()
// configure express to parse JSON
app.use(bodyParser.json())
// view engine setup
app.engine('.hbs', exphbs({
// handlebars templates use the .hbs file extension
extname: '.hbs',
// render within views/layouts/main.hbs
defaultLayout: 'main'
}))
app.set('view engine', '.hbs')
// log HTTP requests to terminal
app.use(logger('dev'))
// serve static assets from 'public' directory
app.use(express.static('public'))
// there's probably a better way to handle this...
app.use('/styles', express.static('node_modules/normalize.css'))
// use our routes
app.use('/', pages)
app.use('/api', api)
// start HTTP server on port 3000
app.listen(3000, () => {
// do it!
console.log('Listening on http://localhost:3000/')
})