-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
97 lines (79 loc) · 2.65 KB
/
app.js
File metadata and controls
97 lines (79 loc) · 2.65 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const cors = require('cors')
const compression = require('compression')
const mongoose = require('mongoose')
const BASE_API_URL = 'http://localhost:1414'
mongoose.connect(`mongodb://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@localhost:27017/dragonfly`,
{ useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false },
console.log('Connected to DB'))
require('dotenv/config')
const MODE = process.env.MODE
const axios = require('axios')
var indexRouter = require('./routes/index');
var authRouter = require('./routes/authentication');
var minecraftRouter = require('./routes/minecraft')
var statisticsRouter = require('./routes/statistics')
var partnerRouter = require('./routes/partner')
var linkRouter = require('./routes/link')
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(cors({ credentials: true }))
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
// const secureAuth = async function (req, res, next) {
// const dragonflyToken = req.cookies["dragonfly-token"]
// const dragonflyAccount = await getDragonflyAccount(dragonflyToken)
// if (!dragonflyToken || !dragonflyAccount) return res.redirect('https://playdragonfly.net/login?ref=https://dashboard.playdragonfly.net');
// next()
// }
// app.use(secureAuth)
// API ROUTES
app.use(compression())
app.use('/link', linkRouter)
app.use('/', indexRouter);
app.use('/partner', partnerRouter)
app.use('/auth', authRouter);
app.use('/minecraft', minecraftRouter)
app.use('/statistics', statisticsRouter)
app.use(function (req, res, next) {
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.render('sites/404');
return;
}
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
async function getDragonflyAccount(token) {
let account;
await axios.post(`${BASE_API_URL}/v1/authentication/token`, {}, {
timeout: 6000,
headers: {
"Authorization": `Bearer ${token}`
}
})
.then(result => {
account = result.data
})
.catch(err => {
console.log(err)
if (err) {
console.log(err)
}
})
return account
}
module.exports = app;