Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-08-29 18:00:10 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dab2ebb51042255517b1961ac4450a52e793dcaf
dab2ebb5
1 parent
919e1168
remove yoga, replace apollo-server
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
8 deletions
back/src/server.js
back/src/server.js
View file @
dab2ebb
import
dotenv
from
"dotenv"
;
dotenv
.
config
();
import
{
GraphQLServer
,
PubSub
}
from
"graphql-yoga"
;
import
express
from
"express"
;
import
bodyParser
from
"body-parser"
;
import
cors
from
"cors"
;
import
helmet
from
"helmet"
;
import
csp
from
"helmet-csp"
;
import
expressPlayground
from
"graphql-playground-middleware-express"
;
import
{
ApolloServer
}
from
"apollo-server-express"
;
import
morgan
from
"morgan"
;
import
"./passport"
;
import
{
authenticateJWT
}
from
"./passport"
;
...
...
@@ -8,14 +14,43 @@ import schema from "./schema";
const
PORT
=
process
.
env
.
PORT
;
const
pubsub
=
new
PubSub
();
const
server
=
new
GraphQLServer
({
const
server
=
new
ApolloServer
({
schema
,
context
:
({
request
})
=>
({
request
,
pubsub
}),
});
server
.
express
.
use
(
morgan
(
"dev"
));
server
.
express
.
use
(
authenticateJWT
);
const
app
=
express
();
app
.
use
(
helmet
());
app
.
use
(
csp
({
directives
:
{
defaultSrc
:
[
"'self'"
],
styleSrc
:
[
"'self'"
,
"'unsafe-inline'"
],
styleSrcElem
:
[
"'self'"
,
"fonts.googleapis.com"
,
"cdn.jsdelivr.net"
,
"'unsafe-inline'"
,
],
imgSrc
:
[
"'self'"
,
"cdn.jsdelivr.net"
],
scriptSrcElem
:
[
"'self'"
,
"cdn.jsdelivr.net"
,
"'unsafe-inline'"
],
fontSrc
:
[
"'self'"
,
"'unsafe-inline'"
,
"fonts.gstatic.com"
],
},
})
);
app
.
use
(
bodyParser
.
json
(),
cors
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
morgan
(
"dev"
));
app
.
use
(
authenticateJWT
);
app
.
get
(
"/"
,
expressPlayground
({
endpoint
:
"/graphql"
}));
server
.
applyMiddleware
({
app
});
const
handleListening
=
()
=>
{
console
.
log
(
`Server ready at http://localhost:
${
PORT
}
`
);
};
server
.
start
(()
=>
console
.
log
(
`server is running : http://localhost:
${
PORT
}
`
)
);
app
.
listen
(
PORT
,
handleListening
);
...
...
Please
register
or
login
to post a comment