-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (65 loc) · 2.38 KB
/
app.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
72
73
74
75
76
77
78
79
80
81
82
83
require('dotenv').config();
require('babel-polyfill');
const express = require('express');
const session = require('express-session');
const app = express();
const bodyParser = require('body-parser');
const ConfigUtils = require('./config/config');
const RateLimit = require('express-rate-limit');
const AuthMiddleware = require('./api/Middleware/AuthMiddleware');
const config = ConfigUtils.loadConfig(process.argv);
const apollo = require('./apollo/server');
const Logger = require('./utils/Logger');
global.fetch = require("node-fetch");
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', '*');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
app.use(bodyParser.raw());
const RateLimiter = new RateLimit({
windowMs: 1000,
max: 100,
delayMs: 0
});
app.use(session({
name: "musicoin-api",
secret: 'mcapi',
cookie: {
maxAge: 60000
}
}));
app.use(RateLimiter);
Logger.initRequestLogger(app);
app.use("/",require('./api/routes/auth'));
app.use("/v1",require('./api/routes/v1/auth'));
app.use("/v1/auth",require('./api/routes/v1/auth'));
// test
app.use('/test/release', require('./api/routes/release'));
app.use('/test/track', require('./api/routes/v1/track'));
app.use("/test", require("./api/routes/v1/global"));
app.use("/manage", require("./api/routes/v1/global"));
app.use('/', AuthMiddleware.authenticate);
app.use("/v1", require("./api/routes/v1/global"));
app.use("/v1/artist", require("./api/routes/v1/artist"));
app.use("/v1/user", require("./api/routes/v1/user"));
app.use("/v1/release", require("./api/routes/v1/release"));
app.use("/v2", require("./api/routes/v2/global"));
app.use("/v2/release", require("./api/routes/v2/release"));
apollo.config(app);
app.use('/', require('./api/routes/global'));
app.use('/user', require('./api/routes/user'));
app.use('/package', require('./api/routes/package'));
app.use('/release', require('./api/routes/release'));
app.use('/license', require('./api/routes/license'));
app.use('/artist', require('./api/routes/artist'));
app.use('/tx', require('./api/routes/tx'));
app.listen(config.port, function() {
Logger.info(`server listening on port ${config.port}`);
});