Skip to content

Commit b3339a6

Browse files
committed
add CORS to node-graphql example
1 parent 108a2db commit b3339a6

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

oss/node-graphql/Readme.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Node GraphQL
33

4-
GraphQL server.
4+
GraphQL server with CORS.
55

66
## Setup
77

@@ -17,6 +17,31 @@ $ up
1717

1818
## Usage
1919

20+
With curl:
21+
2022
```
2123
$ curl -d '{ "query": "{ pet(id: 0) { name }}" }' `up url`?pretty
2224
```
25+
26+
With `fetch()` in the browser:
27+
28+
``js
29+
const body = JSON.stringify({
30+
query: `query {
31+
pet(id: 2) {
32+
name
33+
}
34+
}`
35+
})
36+
37+
const res = await fetch('http://localhost:3000', {
38+
headers: { 'Content-Type': 'application/json' },
39+
method: 'POST',
40+
body
41+
})
42+
43+
console.log(res)
44+
console.log(await res.json())
45+
```
46+
47+
See the [CORS](https://up.docs.apex.sh/#configuration.cross_origin_resource_sharing) second of the documentation for details.

oss/node-graphql/up.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"name": "app"
2+
"name": "app",
3+
"cors": {
4+
"enable": true,
5+
"debug": true
6+
}
37
}

0 commit comments

Comments
 (0)