forked from fastify/fastify-nextjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test-d.ts
66 lines (56 loc) · 1.55 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import fastify, { FastifyInstance } from 'fastify';
import { expectError } from 'tsd';
import fastifyNext from './index';
// Declaration merging for custom property injection
declare module 'http' {
interface IncomingMessage {
server: FastifyInstance
}
}
const app = fastify();
app
.register(fastifyNext, {
logLevel: 'error', // option from Fastify.js, RegisterOptions
underPressure: false, // option from fastify-nextjs, FastifyNextOptions
noServeAssets: false, // option from fastify-nextjs, FastifyNextOptions
dev: true // option from Next.js,
})
.after(() => {
app.setErrorHandler((err, req, reply) => {
reply.log.error({ req, res: reply, err }, 'Internal server error');
return reply.code(500).nextRenderError(err);
});
app.next('/a');
app.next('/*', (nextApp, req, reply) => {
if (!nextApp.options) {
throw new Error("nextApp hasn't options!");
}
return nextApp
.getRequestHandler()(req.raw, reply.raw)
.then(() => {
reply.sent = true;
});
});
app.next('/options-without-schema', {
method: 'GET'
});
app.next(
'/options-with-schema',
{
method: 'POST',
schema: {}
},
async (_, __, reply) => {
reply.send('OK');
}
);
app.next('/options-with-hook-injecting-custom-property', {
onRequest: (req, _, done) => {
req.raw.server = req.server;
done();
},
});
expectError(app.next('/unknown-option', {
invalid: 'unknown-option'
}))
});