-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (46 loc) · 1.42 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
// server.js
// where your node app starts
// init project
const express = require("express");
const app = express();
const server = require("http").createServer(app);
const mustacheExpress = require("mustache-express");
// socket.io
const io = require("socket.io")(server);
// listen for requests :)
const listener = server.listen(process.env.PORT || 3000, function () {
console.log("Your app is listening on port " + listener.address().port);
});
// Setup Templating
app.engine("html", mustacheExpress());
app.set("view engine", "html");
app.set("views", __dirname + "/views");
// http://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));
// http://expressjs.com/en/starter/basic-routing.html
app.get("/", function (request, response) {
response.render("concert", {
isProduction: process.env.ENVIRONMENT === "production",
});
});
app.get("/editor", function (request, response) {
response.render("editor", {
isProduction: process.env.ENVIRONMENT === "production",
});
});
app.get("/current_code_debug", function (request, response) {
response.send({ _code });
});
let _code = undefined;
io.on("connection", function (socket) {
socket.on("livecode-update", function (code) {
console.log("CODE UPDATE:", code);
// save the code here
_code = code;
// broadcast the code too
socket.broadcast.emit("code", _code);
});
socket.on("disconnect", function () {
//
});
});