-
Notifications
You must be signed in to change notification settings - Fork 1
/
route.ts
45 lines (35 loc) · 1.02 KB
/
route.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
import { NextResponse } from 'next/server';
import { handler, Middleware } from '../../middleware/handler';
const middleware_1: Middleware = async (_req, next) => {
console.log('Running middleware 1');
next();
};
const middleware_2: Middleware = async (_req, next) => {
console.log('Running middleware 2');
// sleep for 2.5 seconds
console.log('Sleeping for 2.5 seconds');
await new Promise((resolve) => setTimeout(resolve, 2500));
next();
};
const middleware_3: Middleware = async (_req, next) => {
console.log('Running middleware 3');
// Fetch data from json api
const res = await fetch('https://jsonplaceholder.typicode.com/todos/1');
const json = await res.json();
console.log(json);
next();
};
const middleware_4: Middleware = async (_req, next) => {
console.log('Running middleware 4');
next();
};
const hello = async (req: Request) => {
return NextResponse.json({ data: 'Hello World' });
};
export const GET = handler(
middleware_1,
middleware_2,
middleware_3,
middleware_4,
hello,
);