-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
77 lines (56 loc) · 1.75 KB
/
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
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
// Generated by CoffeeScript 1.3.3
/*
Module dependencies.
*/
(function() {
var app, db, express, http, io, nano, path, routes, socket, user, users;
express = require("express");
socket = require("socket.io");
routes = require("./routes");
user = require("./routes/user");
http = require("http");
path = require("path");
nano = require("nano")('http://localhost:5984');
db = nano.db.use('brownbag1');
app = module.exports = express.createServer();
io = socket.listen(app);
app.configure(function() {
app.set("port", process.env.PORT || 3000);
app.set("views", __dirname + "/views");
app.set("view engine", "jade");
app.use(express.favicon());
app.use(express.logger("dev"));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
return app.use(express["static"](path.join(__dirname, "public")));
});
app.configure("development", function() {
return app.use(express.errorHandler());
});
app.get("/", routes.index);
app.get("/users", user.list);
app.listen(3000, function() {
return console.log("==> Server listening on port %d in %s mode", app.address().port, app.settings.env);
});
users = [];
io.sockets.on("connection", function(socket) {
console.log("User connected");
socket.emit("message", {
message: "Welcome to the brownbag1 chat"
});
socket.on("userName", function(user) {
console.log(user + " has joined");
users.push(user);
return socket.broadcast.emit("message", {
message: user + " has joined"
});
});
return socket.on("chat", function(data) {
console.log(data);
return socket.broadcast.emit("message", {
message: data
});
});
});
}).call(this);