-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (47 loc) · 852 Bytes
/
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
/*!
* chat - app.js
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
*/
const path = require('path');
const koa = require('koa.io');
const fs = require('fs');
let app = koa();
/**
* catch error
*/
app.use(function* (next) {
try {
yield next;
} catch (err) {
console.log(err);
this.status = err.status || 500;
this.body = err.message;
this.app.emit('error', err, this);
}
});
/**
* static file server
*/
const staticCache = require('koa-static-cache');
app.use(staticCache(path.join(__dirname, '/public')));
/**
* router
*/
app.use(function* () {
this.body = fs.createReadStream(path.join(__dirname, 'public/index.html'));
this.type = 'html';
this.status = 200;
});
/**
* socket
*/
require("./socket")(app);
/**
* listen port
*/
app.listen(3000);
console.log(`$ open http://127.0.0.1:3000`);