-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
75 lines (62 loc) · 1.82 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
65
66
67
68
69
70
71
72
73
74
75
const express = require('express')
const graphqlHTTP = require('express-graphql')
const roleSchema = require('./src/role/schema.js')
const userSchema = require('./src/user/schema.js')
const torrentSchema = require('./src/torrent/schema.js')
const kafaSchema = require('./src/kafa/schema.js')
const tokenSchema = require('./src/token/schema.js')
const passport = require('passport')
const mongoose = require('mongoose')
const config = require('./src/config')
const cors = require('cors')
mongoose.Promise = global.Promise
// Connect to Database
mongoose.connect(config.DATABASE_URL, {})
// On Connection
mongoose.connection.on('connected', () => {
console.log('Connected to database ' + config.DATABASE_URL)
})
// On Error
mongoose.connection.on('error', (err) => {
console.log('Database error: ' + err)
})
let port = config.PORT
const app = express()
// Passport Mİddleware
app.use(passport.initialize())
app.use(passport.session())
require('./src/config/passport')(passport)
app.use('/graphql/users', cors(), passport.authenticate('jwt', {
session: false
}), graphqlHTTP(request => ({
schema: userSchema,
rootValue: request,
graphiql: true
})))
app.use('/graphql/torrents', cors(), passport.authenticate('jwt', {
session: false
}), graphqlHTTP(request => ({
schema: torrentSchema,
rootValue: request,
graphiql: true
})))
app.use('/graphql/kafas', cors(), passport.authenticate('jwt', {
session: false
}), graphqlHTTP(request => ({
schema: kafaSchema,
rootValue: request,
graphiql: true
})))
app.use('/graphql/roles', cors(), passport.authenticate('jwt', {
session: false
}), graphqlHTTP(request => ({
schema: roleSchema,
rootValue: request,
graphiql: true
})))
app.use('/graphql/token', cors(), graphqlHTTP({
schema: tokenSchema,
graphiql: true
}))
app.listen(port)
console.log('All hand hoay! -> ' + port)