-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.js
90 lines (68 loc) · 2.29 KB
/
service.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var http = require('http');
var server = http.createServer();
server.listen(8000);
var connect = require('connect')
, express = require('express')
, http = require('http')
, fs = require('fs')
, browserify = require('browserify')
, querystring = require('querystring')
, request = require('request')
, cookieParser = require('cookie-parser')
, serverAuth = require('./auth/server')
var cacheAge = process.env.NODE_ENV === 'production' ? 0 : 60 * 60 * 1000;
app = express()
.use(connect.favicon())
.use(connect.compress()) // must be before static
.use(connect.static('public', { maxAge: cacheAge }))
.use(cookieParser())
.use(function(req, res) {
if (req.url === '/') {
// HTML is implied
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(fs.readFileSync('./index.html'));
}
if (req.url === '/example') {
// HTML is implied
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(fs.readFileSync('./collision-example.html'));
}
if (req.url === '/client.js') {
var b = browserify();
b.add('./client/index.js');
// optional: ignore weird requires
// b.ignore('./lib-cov/merge')
res.writeHead(200, { 'Content-Type': 'text/javascript' });
b.bundle().pipe(res);
}
if (req.url === '/login') {
serverAuth.signIn(req, res)
}
if (req.url.indexOf('/login-callback') !== -1) {
serverAuth.handleCallback(req, res)
}
if (req.url === '/login-success') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(fs.readFileSync('./index.html'));
}
/*
if (req.url === '/faye.js') {
res.writeHead(200, { 'Content-Type': 'text/javascript' });
res.end(fs.readFileSync('./node_modules/faye/browser/faye-browser.js'));
}
if(req.url === '/client.js') {
var b = browserify();
b.add('./client.js');
// Hack annoying tea-type conditional require
b.ignore('./lib-cov/merge')
b.ignore('./lib-cov/type')
b.bundle().pipe(res);
}
if(req.url === '/body') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(fs.readFileSync(file).toString())
}*/
})
var port = process.env.PORT || 8001;
http.createServer(app).listen(port);
console.log("Listening on port", port)