Skip to content

Commit 6182315

Browse files
committed
feat: Add support for turning of csrf protection
1 parent 27541ee commit 6182315

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
"type": "git",
2626
"url": "git+https://github.com/relekang/graphql-rss-parser.git"
2727
},
28-
"files": [
29-
"dist",
30-
"cli.js",
31-
"license",
32-
"readme.md"
33-
],
28+
"files": ["dist", "cli.js", "license", "readme.md"],
3429
"author": "Rolf Erik Lekang",
3530
"license": "MIT",
3631
"bugs": {

src/cli.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import type { ApolloServer } from "@apollo/server";
22
import { startStandaloneServer } from "@apollo/server/standalone";
3-
import { command, number, option, optional, run, string } from "cmd-ts";
3+
import {
4+
boolean,
5+
command,
6+
flag,
7+
number,
8+
option,
9+
optional,
10+
run,
11+
string,
12+
} from "cmd-ts";
413
import type { Options } from "./index.js";
514

615
export function cli({
@@ -44,14 +53,27 @@ export function cli({
4453
return undefined;
4554
},
4655
}),
56+
csrfPrevention: flag({
57+
type: boolean,
58+
short: "C",
59+
long: "csrf-prevention",
60+
description: "Toggle for CSRF prevention",
61+
env: "CSRF_PREVENTION",
62+
defaultValue() {
63+
return false;
64+
},
65+
}),
4766
},
4867
handler: async (args) => {
4968
const server = await createServer({
5069
version,
5170
sentryDsn: args.sentryDsn,
71+
csrfPrevention: args.csrfPrevention,
5272
});
5373

54-
console.log(`Starting graphql-rss-parser v${version}`);
74+
console.log(
75+
`Starting graphql-rss-parser v${version} with ${JSON.stringify({ ...args }, null, 2)}`,
76+
);
5577
const { url } = await startStandaloneServer(server, {
5678
context: async ({ req }) => ({ token: req.headers.token }),
5779
listen: { host: args.host, port: args.port },

src/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ export function createErrorFormatter(
187187
console.error(
188188
new Date().toISOString(),
189189
"-",
190-
originalError.message,
191-
originalError.code ? "-" : "",
192-
originalError.code ? originalError.code : "",
190+
(originalError ?? error).message,
191+
originalError?.code ? "-" : "",
192+
originalError?.code ? originalError.code : "",
193193
);
194194

195195
return response;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { schema } from "./schema.js";
66
export type Options = {
77
version: string;
88
sentryDsn?: string;
9+
csrfPrevention: boolean;
910
};
1011

1112
export default async function createServer(
@@ -33,6 +34,7 @@ export default async function createServer(
3334
schema,
3435
formatError,
3536
persistedQueries: false,
37+
csrfPrevention: options.csrfPrevention,
3638
});
3739

3840
return apolloServer;

0 commit comments

Comments
 (0)