forked from x-team/daw-purchases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (26 loc) · 754 Bytes
/
index.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
'use strict'
var http = require('http')
var Router = require('http-hash-router')
var path = require('path')
var port = process.env.PORT || 8000
var router = new Router()
var store = require('./src/setup-store')(path.join(__dirname, '.data'))
// ----
// setup the http server
var server = http.createServer(function handler (req, res) {
router(req, res, {}, function onError (err) {
if (err) {
res.statusCode = err.statusCode || 500
res.end(err.message)
}
})
})
// ----
// add routes
require('./src/routes/products')(router, store)
require('./src/routes/purchases')(router, store)
require('./src/routes/users')(router, store)
// ----
// start the server
server.listen(port)
console.log('ready on http://0.0.0.0:%d', port)