File tree 2 files changed +13
-4
lines changed
src/packages/server/src/integrations
2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ export const startStandaloneServer = async <TContext extends BaseContext>(
47
47
onRequestWrapper ( plugins , async ( ) => done ( ) ) ;
48
48
} ) ;
49
49
50
+ // Always flush the logger on each request so logs get persisted.
51
+ fastify . addHook ( 'onResponse' , async ( ) => logger . flush ( ) ) ;
52
+
50
53
fastify . get ( '/health' , async ( _ , reply ) => {
51
54
reply . statusCode = 200 ;
52
55
reply . send ( {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { ApolloServer } from '@apollo/server';
2
2
import { handlers , startServerAndCreateLambdaHandler } from '@as-integrations/aws-lambda' ;
3
3
import { GraphweaverPlugin } from '@exogee/graphweaver' ;
4
4
import { onRequestWrapper } from './utils' ;
5
+ import { logger } from '@exogee/logger' ;
5
6
6
7
export const startServerless = ( {
7
8
server,
@@ -17,10 +18,15 @@ export const startServerless = ({
17
18
18
19
return ( event , context ) =>
19
20
onRequestWrapper ( graphweaverPlugins , async ( ) => {
20
- const res = await handler ( event , context , ( ) => { } ) ;
21
- if ( ! res ) {
22
- throw new Error ( 'Handler Response was undefined or null.' ) ;
21
+ try {
22
+ const res = await handler ( event , context , ( ) => { } ) ;
23
+ if ( ! res ) {
24
+ throw new Error ( 'Handler Response was undefined or null.' ) ;
25
+ }
26
+ return res ;
27
+ } finally {
28
+ // Ensure we always flush logs on each request.
29
+ logger . flush ( ) ;
23
30
}
24
- return res ;
25
31
} ) ;
26
32
} ;
You can’t perform that action at this time.
0 commit comments