-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
62 lines (45 loc) · 1.54 KB
/
index.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
// bcb-server
// var app = require('express')();
// var http = require('http').createServer(app);
// var io = require('socket.io')(http);
// app.get('/', function(req, res){
// res.sendFile(__dirname + '/www/index.html');
// });
// io.on('connection', function(socket){
// console.log('a user connected');
// });
// http.listen(3000, function(){
// console.log('listening on *:3000');
// });
// var http = require('http');
// http.createServer(function (req, res) {
// res.writeHead(200, {'Content-Type': 'text/plain'});
// res.end('Hello World\n');
// }).listen(8080, 'localhost');
// console.log('Server running at http://localhost:8080/');
var path = require('path')
var express = require('express')
var app = express();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
app.use('/js', express.static(path.join(__dirname, 'www/js')))
app.use('/font', express.static(path.join(__dirname, 'www/font')))
app.use('/css', express.static(path.join(__dirname, 'www/css')))
app.use('/res', express.static(path.join(__dirname, 'www/res')))
app.use('/media', express.static(path.join(__dirname, 'www/media')))
app.get('/', function(req, res){
res.sendFile(__dirname + '/www/index.html');
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
socket.on('mqtt', function(data){
console.log('mqtt', data);
io.emit('mqtt', data)
});
});
http.listen(8080, function(){
console.log('listening on *:8080');
});