1 | "use strict";
|
2 | process.chdir(__dirname);
|
3 | var opinion = require('../..');
|
4 | var conf = require('./conf');
|
5 | var request = require('request');
|
6 |
|
7 | var app = opinion({
|
8 | middlewareOrder: opinion.DEFAULT_MIDDLEWARE_STACK,
|
9 | keys: ['78fd9fe83f2af46f2a8b567154db8d2a'],
|
10 | statics: 'assets',
|
11 | render: ['views', 'dust']
|
12 | });
|
13 |
|
14 |
|
15 | app.get('/',
|
16 | function* () {
|
17 | yield this.render('hello-world');
|
18 | }
|
19 | );
|
20 |
|
21 | app.get('/2',
|
22 | function* () {
|
23 | this.type = 'text/html;charset=UTF-8';
|
24 | this.body = request("http://www.example.com/");
|
25 | }
|
26 | );
|
27 |
|
28 |
|
29 | app.get('/snippet/:user/:id', function* () {
|
30 | this.set('Access-Control-Allow-Origin', '*');
|
31 | this.set('Access-Control-Allow-Methods', 'GET');
|
32 | this.set('Access-Control-Allow-Headers', 'Content-Type');
|
33 | this.type = 'application/javascript';
|
34 | this.body = request('https://gist.github.com/' + this.params.user + '/' + this.params.id + '/raw');
|
35 | });
|
36 |
|
37 |
|
38 | app.listen(conf.PORT, function () {
|
39 | console.log("Server listening on %s", this._connectionKey);
|
40 | });
|
41 |
|
42 |
|
43 | setInterval(function () {
|
44 | app.webSockets.emit('gaga', new Date + '\n' + JSON.stringify(process.memoryUsage()));
|
45 | }, 3000);
|