UNPKG

1.14 kBJavaScriptView Raw
1"use strict";
2process.chdir(__dirname);
3var opinion = require('../..');
4var conf = require('./conf');
5var request = require('request');
6
7var app = opinion({
8 middlewareOrder: opinion.DEFAULT_MIDDLEWARE_STACK,
9 keys: ['78fd9fe83f2af46f2a8b567154db8d2a'],
10 statics: 'assets',
11 render: ['views', 'dust']
12});
13
14
15app.get('/',
16 function* () {
17 yield this.render('hello-world');
18 }
19);
20
21app.get('/2',
22 function* () {
23 this.type = 'text/html;charset=UTF-8';
24 this.body = request("http://www.example.com/");
25 }
26);
27
28
29app.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
38app.listen(conf.PORT, function () {
39 console.log("Server listening on %s", this._connectionKey);
40});
41
42
43setInterval(function () {
44 app.webSockets.emit('gaga', new Date + '\n' + JSON.stringify(process.memoryUsage()));
45}, 3000);