forked from snoopysecurity/dvws-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
88 lines (64 loc) · 2.58 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
84
85
86
87
88
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const swaggerUI = require('swagger-ui-express');
const fileUpload = require('express-fileupload');
const path = require('path');
const swaggerDocument = require('./swagger'); //Swagger
const soapservice = require('./soapserver/dvwsuserservice'); //SOAP Service
const rpcserver = require('./rpc_server'); //XMLRPC Sever
const { ApolloServer } = require('apollo-server');
const { GqSchema } = require('./graphql/schema');
const app = express();
const router = express.Router();
const routes = require('./routes/index.js');
app.use(express.static('public'));
app.use("/css", express.static(path.join(__dirname, "node_modules/bootstrap/dist/css")));
app.use("/js", express.static(path.join(__dirname, "node_modules/bootstrap/dist/js")));
app.use("/js", express.static(path.join(__dirname, "node_modules/jquery/dist")));
app.use("/js", express.static(path.join(__dirname, "node_modules/angular")));
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument));
app.use('/dvwsuserservice', soapservice);
app.use(bodyParser.json());
app.use(fileUpload({ parseNested: true }));
const jwt = require('jsonwebtoken')
const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
algorithms: ["HS256", "none"],
ignoreExpiration: true
};
var corsOptions = {
origin: true,
credentials: true,
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}
app.use(cors(corsOptions))
app.use('/api', routes(router));
app.listen(process.env.EXPRESS_JS_PORT, () => {
console.log(`🚀 API listening at http://dvws.local${process.env.EXPRESS_JS_PORT == 80 ? "" : ":" + process.env.EXPRESS_JS_PORT } (127.0.0.1)`);
});
// The ApolloServer constructor requires two parameters: your schema
// definition and your set of resolvers.
const server = new ApolloServer({
introspection: true,
playground: true,
debug: true,
allowBatchedHttpRequests: true,
schema: GqSchema,
context: async ({ req }) => {
let verifiedToken = {}
try {
const token = req.headers.authorization.split(' ')[1]; // Bearer <token>
verifiedToken = jwt.verify(token, process.env.JWT_SECRET, options);
} catch (error) {
verifiedToken = {}
}
return verifiedToken;
}, });
server.listen({ port: process.env.GRAPHQL_PORT }).then(({ url }) => {
console.log(`🚀 GraphQL Server ready at ${url}`);
});;
module.exports = app;