Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Labels
Plan
Issues
25
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cokoapps
server
Commits
6232cb5f
Commit
6232cb5f
authored
2 years ago
by
Yannis Barlas
Browse files
Options
Downloads
Patches
Plain Diff
feat(server): pass cors config to apollo server
parent
f17e633e
No related branches found
No related tags found
2 merge requests
!52
Docx
,
!17
Graphql api
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/app.js
+3
-10
3 additions, 10 deletions
src/app.js
src/corsConfig.js
+14
-0
14 additions, 0 deletions
src/corsConfig.js
src/graphqlApi.js
+4
-1
4 additions, 1 deletion
src/graphqlApi.js
with
21 additions
and
11 deletions
src/app.js
+
3
−
10
View file @
6232cb5f
...
@@ -20,6 +20,7 @@ const api = require('pubsweet-server/src/routes/api')
...
@@ -20,6 +20,7 @@ const api = require('pubsweet-server/src/routes/api')
const
index
=
require
(
'
pubsweet-server/src/routes/index
'
)
const
index
=
require
(
'
pubsweet-server/src/routes/index
'
)
const
healthcheck
=
require
(
'
./healthcheck
'
)
const
healthcheck
=
require
(
'
./healthcheck
'
)
const
createCORSConfig
=
require
(
'
./corsConfig
'
)
const
configureApp
=
app
=>
{
const
configureApp
=
app
=>
{
const
models
=
require
(
'
@pubsweet/models
'
)
const
models
=
require
(
'
@pubsweet/models
'
)
...
@@ -61,16 +62,8 @@ const configureApp = app => {
...
@@ -61,16 +62,8 @@ const configureApp = app => {
}
}
// Allow CORS from client if host / port is different
// Allow CORS from client if host / port is different
if
(
config
.
has
(
'
pubsweet-client.url
'
))
{
const
CORSConfig
=
createCORSConfig
()
const
clientUrl
=
config
.
has
(
'
clientUrl
'
)
&&
config
.
get
(
'
clientUrl
'
)
app
.
use
(
cors
(
CORSConfig
))
app
.
use
(
cors
({
origin
:
clientUrl
,
credentials
:
true
,
}),
)
}
// Register passport authentication strategies
// Register passport authentication strategies
app
.
use
(
passport
.
initialize
())
app
.
use
(
passport
.
initialize
())
...
...
This diff is collapsed.
Click to expand it.
src/corsConfig.js
0 → 100644
+
14
−
0
View file @
6232cb5f
const
config
=
require
(
'
config
'
)
const
createCORSConfig
=
()
=>
{
if
(
!
config
.
has
(
'
pubsweet-client.url
'
))
return
null
const
clientUrl
=
config
.
has
(
'
clientUrl
'
)
&&
config
.
get
(
'
clientUrl
'
)
return
{
origin
:
clientUrl
,
credentials
:
true
,
}
}
module
.
exports
=
createCORSConfig
This diff is collapsed.
Click to expand it.
src/graphqlApi.js
+
4
−
1
View file @
6232cb5f
const
{
graphqlUploadExpress
}
=
require
(
'
graphql-upload
'
)
const
{
graphqlUploadExpress
}
=
require
(
'
graphql-upload
'
)
const
createGraphQLServer
=
require
(
'
./graphqlServer
'
)
const
createGraphQLServer
=
require
(
'
./graphqlServer
'
)
const
createCORSConfig
=
require
(
'
./corsConfig
'
)
const
api
=
app
=>
{
const
api
=
app
=>
{
app
.
use
(
app
.
use
(
...
@@ -13,7 +14,9 @@ const api = app => {
...
@@ -13,7 +14,9 @@ const api = app => {
app
.
use
(
graphqlUploadExpress
())
app
.
use
(
graphqlUploadExpress
())
const
server
=
createGraphQLServer
()
const
server
=
createGraphQLServer
()
server
.
applyMiddleware
({
app
})
const
CORSConfig
=
createCORSConfig
()
server
.
applyMiddleware
({
app
,
cors
:
CORSConfig
})
}
}
module
.
exports
=
api
module
.
exports
=
api
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment