-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathserver.js
72 lines (61 loc) · 1.79 KB
/
server.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
// Basic server to serve static assets from /public folder
// with a proxy for XMPP server BOSH interface
var util = require('util'),
express = require('express'),
partials = require('express-partials'),
httpProxy = require('http-proxy');
var app = express(),
proxy = new httpProxy.HttpProxy({
target: {
host: 'localhost',
port: 5280 // Port of XMPP server
}
});
app.configure(function() {
app.use(express.static(__dirname));
app.use(partials());
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({secret: 'f7cd7374c2851fb727582bf'}));
});
app.set('view engine', 'ejs');
app.configure("development", function () {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.get('/', function (req, res) {
if (!req.session.user) {
res.redirect('/sign_in');
} else {
res.render('index', {
locals: {
user: req.session.user
}
});
}
});
app.get('/sign_in', function (req, res) {
if (req.session.user) {
res.redirect('/');
} else {
res.render('sign_in');
}
});
app.post('/sign_in', function (req, res) {
req.session.user = {
name: req.body.name,
password: req.body.password
};
res.redirect('/');
});
app.get('/sign_out', function (req, res) {
delete req.session.user;
res.redirect('/sign_in');
});
// Proxy BOSH request to XMPP server
app.all('/http-bind', function(req, res) {
util.puts('Request successfully proxied: ' + req.url);
util.puts(JSON.stringify(req.headers, true, 2));
proxy.proxyRequest(req, res);
});
app.listen(9677); // XMPP
util.puts("Server running at http://0.0.0.0:9677/ in " + app.set("env") + " mode.");