Skip to content

Commit c3d6f22

Browse files
authored
Merge pull request #28 from marmelab/cors
[RFR] Add support for CORS in CLI tool
2 parents 56b7b35 + 0d84d85 commit c3d6f22

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ watch-test: ## Launch unit tests and watch for changes
2020

2121
format: ## Format the source code
2222
@./node_modules/.bin/eslint --fix ./src
23+
24+
run: ## Launch server with example data
25+
@node ./bin/json-graphql-server.js example/data.js

bin/json-graphql-server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const path = require('path');
44
const express = require('express');
5+
const cors = require('cors');
56
const JsonGraphqlServer = require('../src/');
67

78
// fixme the build fails without those
@@ -14,6 +15,7 @@ var data = require(path.join(process.cwd(), dataFilePath));
1415
var PORT = 3000;
1516
var app = express();
1617

18+
app.use(cors());
1719
app.use('/', JsonGraphqlServer.jsonGraphqlExpress(data));
1820
app.listen(PORT);
1921
var msg = `GraphQL server running with your data at http://localhost:${PORT}/`;

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-graphql-server",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"main": "src/index",
55
"repository": "[email protected]:marmelab/json-graphql-server.git",
66
"authors": ["François Zaninotto", "Gildas Garcia"],
@@ -10,7 +10,8 @@
1010
"format": "make format",
1111
"precommit": "lint-staged",
1212
"test": "jest",
13-
"watch-test": "make watch-test"
13+
"watch-test": "make watch-test",
14+
"server": "make run"
1415
},
1516
"lint-staged": {
1617
"src/**/*.js": ["eslint --fix", "git add"]
@@ -48,6 +49,7 @@
4849
"dependencies": {
4950
"apollo-client": "~1.2.0",
5051
"apollo-test-utils": "~0.3.2",
52+
"cors": "^2.8.4",
5153
"express": "~4.15.3",
5254
"express-graphql": "~0.6.7",
5355
"graphql": "~0.10.5",

yarn.lock

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,13 @@ [email protected], core-util-is@~1.0.0:
13051305
version "1.0.2"
13061306
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
13071307

1308+
cors@^2.8.4:
1309+
version "2.8.4"
1310+
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.4.tgz#2bd381f2eb201020105cd50ea59da63090694686"
1311+
dependencies:
1312+
object-assign "^4"
1313+
vary "^1"
1314+
13081315
cosmiconfig@^1.1.0:
13091316
version "1.1.0"
13101317
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-1.1.0.tgz#0dea0f9804efdfb929fbb1b188e25553ea053d37"
@@ -3328,7 +3335,7 @@ oauth-sign@~0.8.1:
33283335
version "0.8.2"
33293336
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
33303337

3331-
object-assign@^4.0.1, object-assign@^4.1.0:
3338+
object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0:
33323339
version "4.1.1"
33333340
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
33343341

@@ -4464,6 +4471,10 @@ validate-npm-package-license@^3.0.1:
44644471
spdx-correct "~1.0.0"
44654472
spdx-expression-parse "~1.0.0"
44664473

4474+
vary@^1:
4475+
version "1.1.2"
4476+
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
4477+
44674478
vary@~1.1.1:
44684479
version "1.1.1"
44694480
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.1.tgz#67535ebb694c1d52257457984665323f587e8d37"

0 commit comments

Comments
 (0)