-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (51 loc) · 1.61 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
63
64
65
const express = require('express');
const bodyparser = require('body-parser');
const cors = require('cors');
const logger = require('./utils/logger/logger');
const mongoose = require("mongoose");
const webSocketServer = require("./utils/websocket/websocket");
const random = require("random-string-alphanumeric-generator");
const spotify_class = require('./utils/spotify/spotify');
const http = require("http");
require('dotenv').config();
spotify_class.seed()
//importing routes
const google = require('./routes/google');
const spotify = require('./routes/spotify');
const song = require('./routes/app')
//mongoose models
const Room = require('./models/room');
const Socket = require('./models/socket');
//connecting to database
mongoose.connect('mongodb://localhost:27017/melodyDb', {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
logger.info("connected to database")
}).catch(err => {
logger.error(`error connecting to database ${err}`);
})
//create an instance of express
const app = express();
//create an instance of http server
const httpServer = new http.createServer()
app.use(bodyparser.json());
app.use(cors());
//define port to start the server on
const port = process.env.PORT || 8000
//bind routes to app
app.use('/auth', google);
app.use('/spotify', spotify);
app.use('/api/song',song)
app.get('/',(req,res)=>{
spotify_class.getNewAccessToken()
res.json({msg:"ok"})
})
//bind the port to the app instance
app.listen(port, () => {
logger.info(`Express server started at port: ${port}`);
})
// setInterval(() => {
// console.log("updating")
// spotify_class.stateUpdate()
// }, 3000);