forked from JasonHorine/cloudlogr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
73 lines (51 loc) · 1.87 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
var express = require('express');
var app = express();
app.use(express.static('public'));
var port = process.env.PORT || 3000;
// app.listen(port);
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
var mongoose = require('mongoose');
mongoose.connect(process.env.DB_CONN_CLOUDLOGR); // database on mlab via environment variable
// EWON_DEV_ID ...eWON environment variables
// EWON_ACCOUNT
// EWON_USER_ID
// EWON_USER_PASSWORD
var tankRouter = require("./routes/tankdata"); // tankRouter uses ./routes/tankdata.js file
app.use('/tank', tankRouter); // anything to /tank use tankRouter
app.use('/', tankRouter); // anything to / use tankRouter
var apiRouterv1 = require("./routes/api/v1"); // apiRouterv1 uses ./routes/api/v1.js file
app.use('/api/v1', apiRouterv1); // anything to /api/v1 use apiRouterv1
var apiRouterv2 = require("./routes/api/v2"); // apiRouterv2 uses ./routes/api/v2.js file
app.use('/api/v2', apiRouterv2); // anything to /api/v2 use apiRouterv2
console.log('Server started on ' + port);
app.set('views', './views');
app.set('view engine', 'ejs');
//app.get('/', function(request, response) {
// response.render('index');
//});
//middleware
app.use(function(request, response, next) {
console.log('Time:', Date.now());
next();
});
// Create HTTP server.
var http = require('http');
var server = http.createServer(app);
// Listen on provided port, on all network interfaces.
server.listen(port);
// for socket io:
var io = require('socket.io')(server);
// var http = require('http').Server(app);
// var io = require('socket.io')(http);
// socket io
io.on('connection', function(socket){
//console.log('a user connected');
socket.on('disconnect', function(){
//console.log('user disconnected');
});
});
// socket io
// http.listen(3000, function(){
// console.log('listening on *:3000');
// });