-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
71 lines (58 loc) · 1.93 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
70
71
const express = require('express');
const chalk = require('chalk');
const router = require('./router');
const mongoose = require('mongoose');
const user_average_database = require("./model");
const app = express();
app.use(express.static('frontend'));
app.set('view engine', 'ejs');
app.use(express.json());
app.use(express.urlencoded());
app.use(router);
const get_user_data = require('./bot');
const PORT = process.env.PORT || 3000;
let uri = `mongodb+srv://admin:${process.env.DATABASE_PASSWORD}@cluster0.gnlov.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`;
mongoose.connect(uri,{
useUnifiedTopology: true,
useNewUrlParser: true
});
const connection = mongoose.connection;
connection.once("open", () => {
console.log("MongoDB database connection established successfully");
});
app.get('/api', (req, res) => {
// let username = process.env.PRONOTE_USERNAME;
// let password = process.env.PRONOTE_PASSWORD;
// let link = process.env.PRONOTE_LINK;
const username = req.query.username;
const password = req.query.password;
const link = req.query.link;
if (username && password && link) {
get_user_data(username, password, link)
.then(user_data => {
res.status(200);
res.json(user_data);
});
} else {
console.log("No parameter")
res.sendFile(__dirname + '/frontend/error.html');
}
});
app.post('/',(req,res)=>{
const username = req.body.username;
const password = req.body.password;
const link = req.body.link;
if (username && password && link) {
get_user_data(username, password, link)
.then(user_data => {
res.status(200);
res.json(user_data);
});
} else {
console.log("No parameter")
res.sendFile(__dirname + '/frontend/error.html');
}
});
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});