-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (46 loc) · 1.19 KB
/
index.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
const resolvers = require('./graphql/resolvers/index.js');
const typeDefs = require('./graphql/typeDef');
const {ApolloServer} = require("apollo-server-express");
require("dotenv").config();
const express = require('express');
const { verifyToken } = require('./verifyToken.js');
const app = express();
const server = new ApolloServer({
typeDefs,
resolvers,
context: async ({ req })=>{
let user = "";
const authHeader= req.headers.authorization || "";
try {
if(authHeader){
const token = authHeader.split(" ")[1];
const payload = await verifyToken(token);
user = payload ? payload.sub : "";
}
} catch (error) {
console.error(error);
}
return {
req ,
user
}
},
});
server.applyMiddleware({app , path:'/graphql'});
const port = process.env.PORT || 8080;
app.post('/userData' , (req,res,next)=>{
console.log(req.query);
if(req.query.logCount == 1){
console.log("here");
}
res.send("success");
next();
});
app.get('/userData' , (req,res,next)=>{
console.log(req.params);
res.send("user here")
next();
});
app.listen({port}, async() =>{
console.log(`Server ready at http://localhost:${port}`);
});