-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
64 lines (53 loc) · 1.68 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
const express = require("express");
const cors = require("cors");
const bodyParser = require('body-parser')
const path = require("path");
const connectDB = require("./config/database");
const { graphqlHTTP } = require('express-graphql');
const multer = require('multer');
const schema = require('./GraphQL/query');
const { graphqlUploadExpress } = require('graphql-upload')
const UserImageUpload = require('./controllers/kanban/UserImageUpload');
const UserImageFetch = require('./controllers/kanban/UserImageFetch');
// store config variables in dotenv
require('dotenv').config();
//server creation
const app = express();
//security and cors policy
//app.use(cors({credentials: true, origin: `${process.env.ALLOWEDORIGIN}`, exposedHeaders:['Authorization']}));
app.use(cors({credentials: true, origin: "http://localhost:3000", exposedHeaders:['Authorization']}));
//Init BodyParser
app.use(bodyParser.json({
limit: '50mb'
}))
app.use(bodyParser.urlencoded({
extended: false,
limit: '50mb',
parameterLimit: 100000
}))
//connect to database
connectDB();
//route Init
app.get("/", (req, res) =>
res.sendFile(path.join(__dirname, "public", "index.html"))
);
app.use('/graphql',
graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 })
,(req,res) => {
graphqlHTTP({
schema,
graphiql: true,
context: {req,res}
})(req,res);
}
)
//Init multer
const multerMid = multer({
storage: multer.memoryStorage(),
limits: {
fileSize: 10 * 1024 * 1024, //10MB
},
});
app.post("/UserImageUpload", multerMid.single("file"), UserImageUpload);
app.post("/UserImageFetch", UserImageFetch)
module.exports = app;