forked from aiverify-foundation/aiverify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.mjs
52 lines (40 loc) · 1.29 KB
/
app.mjs
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
import { expressMiddleware } from '@apollo/server/express4';
import express from 'express';
import http from 'http';
import cors from 'cors';
import bodyParser from 'body-parser';
import "dotenv/config.js";
import uploadRouter from './routes/upload.mjs';
import { createApolloServer } from './graphql/server.mjs';
const app = express();
app.use(cors());
app.use(express.urlencoded({ extended: true }));
const httpServer = http.createServer(app);
// connect the db
import mongodb from './lib/mongodb.mjs';
const server = createApolloServer(httpServer);
await server.start();
app.use(
'/graphql',
// cors(),
bodyParser.json(),
expressMiddleware(server),
);
app.use(
"/upload",
cors(),
bodyParser.json(),
uploadRouter
);
// app.post("/testing", (req, res) => {
// console.log('Request body received at /testing is: ', req.body)
// })
/* setup the routes */
import reportRouter from './routes/report.mjs';
app.use("/report", reportRouter);
import templateRouter from './routes/template.mjs';
app.use("/template", templateRouter);
import logsRouter from './routes/logs.mjs';
app.use("/logs", logsRouter);
await new Promise((resolve) => httpServer.listen({ port: 4000 }, resolve));
console.log(`🚀 Server ready at http://localhost:4000`);