-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
53 lines (44 loc) · 1.19 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
// --------------------------------------------------------
// Copyright (c) 2015 by Greg Reimer <[email protected]>
// MIT License. See license.txt for more info.
/*
* Here's our main server app. This doesn't actually
* run a server, it just exports a koa app that can
* be run from anywhere, for example from gulp for dev,
* or from a special runner script in deployment.
*/
'use strict'
import koa from 'koa'
import templates from 'lib/template-helper'
import fileService from 'koa-static'
const app = koa()
export default app
// logging -----------------------
app.use(function*(next) {
try {
yield next
} finally {
console.log('%s %s %s %s',
new Date().toISOString(),
this.request.method,
this.request.url,
this.response.status
)
}
})
// add status (hackish) -----------------------
// open to suggestions of a better way here
app.use(function*(next) {
try {
yield next
} catch(ex) {
this.response.status = ex.status || 500
throw ex
}
})
// serve out of static dir -----------------------
app.use(fileService(__dirname + '/static', {}))
// send page -----------------------
app.use(function*() {
this.body = templates('/app.html', {})
})