-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (37 loc) · 1.04 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
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.disable("x-powered-by");
app.use(function (req, res, next) {
res.setHeader("X-Powered-By", "ASP.NET");
return next();
});
const db = require('./models');
db.mongoose.connect(db.url, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log("Connected to the database!");
})
.catch(err => {
console.log("Cannot connect to the database!", err);
process.exit();
});
async function check() {
const svm = await db.auth.find({_id: 'secure-vote'});
if(svm.length === 0) {
const auth = new db.auth({
_id: process.env.ACCESS_USER,
token: process.env.ACCESS_TOKEN
});
auth.save(auth);
}
}
check();
require('./routes/keys.routes')(app);
const PORT = process.env.PORT || 8081;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});