Skip to content

Commit 6ec174a

Browse files
authored
feat(gatsby): api functions config (#35393)
1 parent 5d85977 commit 6ec174a

18 files changed

+1978
-189
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
GatsbyFunctionConfig,
3+
GatsbyFunctionRequest,
4+
GatsbyFunctionResponse,
5+
} from "gatsby"
6+
import { inspect } from "util"
7+
8+
export default function bodyParserJsonLimit(
9+
req: GatsbyFunctionRequest<Record<any, any>>,
10+
res: GatsbyFunctionResponse
11+
): void {
12+
res.send({
13+
body: inspect(req.body, { depth: Infinity, maxStringLength: 100 }),
14+
})
15+
}
16+
17+
export const config: GatsbyFunctionConfig = {
18+
bodyParser: {
19+
json: {
20+
limit: `100mb`,
21+
},
22+
},
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { inspect } from "util"
2+
3+
export default function bodyParserJsonType(req, res) {
4+
res.send({
5+
body: inspect(req.body, { depth: Infinity, maxStringLength: 100 }),
6+
})
7+
}
8+
9+
export const config = {
10+
bodyParser: {
11+
json: {
12+
type: `*/*`,
13+
},
14+
},
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { inspect } from "util"
2+
3+
export default function bodyParserRawLimit(req, res) {
4+
res.send({
5+
body: inspect(req.body, { depth: Infinity, maxStringLength: 100 }),
6+
})
7+
}
8+
9+
export const config = {
10+
bodyParser: {
11+
raw: {
12+
limit: `100mb`,
13+
},
14+
},
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { inspect } from "util"
2+
3+
export default function bodyParserRawType(req, res) {
4+
res.send({
5+
body: inspect(req.body, { depth: Infinity, maxStringLength: 100 }),
6+
})
7+
}
8+
9+
export const config = {
10+
bodyParser: {
11+
raw: {
12+
type: `*/*`,
13+
},
14+
},
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { inspect } from "util"
2+
3+
export default function bodyParserTextLimit(req, res) {
4+
res.send({
5+
body: inspect(req.body, { depth: Infinity, maxStringLength: 100 }),
6+
})
7+
}
8+
9+
export const config = {
10+
bodyParser: {
11+
text: {
12+
limit: `100mb`,
13+
},
14+
},
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { inspect } from "util"
2+
3+
export default function bodyParserTextType(req, res) {
4+
res.send({
5+
body: inspect(req.body, { depth: Infinity, maxStringLength: 100 }),
6+
})
7+
}
8+
9+
export const config = {
10+
bodyParser: {
11+
text: {
12+
type: `*/*`,
13+
},
14+
},
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { inspect } from "util"
2+
3+
export default function bodyParserUrlUncodedLimit(req, res) {
4+
res.send({
5+
body: inspect(req.body, {
6+
depth: Infinity,
7+
maxStringLength: 100,
8+
}),
9+
})
10+
}
11+
12+
export const config = {
13+
bodyParser: {
14+
urlencoded: {
15+
limit: `100mb`,
16+
extended: true,
17+
},
18+
},
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { inspect } from "util"
2+
3+
export default function bodyParserUrlencodedType(req, res) {
4+
res.send({
5+
body: inspect(req.body, { depth: Infinity, maxStringLength: 100 }),
6+
})
7+
}
8+
9+
export const config = {
10+
bodyParser: {
11+
urlencoded: {
12+
type: `*/*`,
13+
extended: true
14+
},
15+
},
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { inspect } from "util"
2+
3+
export default function bodyParserFalse(req, res) {
4+
res.send({
5+
body: inspect(req.body, { depth: Infinity, maxStringLength: 100 }),
6+
})
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default (req, res) => {
2+
throw new Error(`some error`)
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const something = (req, res) => {
2+
res.send(`ok`)
3+
}

0 commit comments

Comments
 (0)