-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
69 lines (41 loc) · 1.43 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
// var env = require("node-env-file");
// env(__dirname + '/.env');
var express = require("express");
var bodyParser = require("body-parser");
var cronJob = require('cron').CronJob;
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/downloads'));
var ejs = require('ejs');
app.engine('html',ejs.renderFile);
app.set('view engine','html');
var controllers = require('./controllers');
app.post('/api/users', controllers.users.create);
app.get('/api/users/:user/songs', controllers.usersongs.index);
app.post('/api/users/:user/songs', controllers.usersongs.create);
app.get('/api/*', function noRoute (req, res) {
res.status(404).json("Sorry, nothing was found");
});
app.post('/swap', controllers.auth.tokenSwap);
app.post('/refresh', controllers.auth.tokenRefresh);
app.get('/downloads/iphoneimage', function (req,res){
res.sendFile('./public/media/iphone6_2.jpg');
});
app.get('*', function (req,res){
res.render('index.html');
});
var job = new cronJob({
cronTime: '00 00 00 * * *',
onTick: function(){
console.log("running maintainence");
controllers.maintainence.removeOldSongs();
},
start: false,
timeZone: "America/Los_Angeles"
});
app.listen(process.env.PORT || 3000, function () {
// job.start();
console.log('Express server is running on http://localhost:3000/');
});