21
21
// functions with HTTP trigger).
22
22
23
23
import * as bodyParser from 'body-parser' ;
24
+ // eslint-disable-next-line node/no-deprecated-api
24
25
import * as domain from 'domain' ;
25
26
import * as express from 'express' ;
26
27
import * as http from 'http' ;
27
28
import * as onFinished from 'on-finished' ;
28
29
29
- import { FUNCTION_STATUS_HEADER_FIELD } from './types' ;
30
- import { logAndSendError } from './logger' ;
31
- import { isBinaryCloudEvent , getBinaryCloudEventContext } from './cloudevents' ;
30
+ import { FUNCTION_STATUS_HEADER_FIELD } from './types' ;
31
+ import { logAndSendError } from './logger' ;
32
+ import { isBinaryCloudEvent , getBinaryCloudEventContext } from './cloudevents' ;
32
33
import {
33
34
HttpFunction ,
34
35
EventFunction ,
@@ -41,6 +42,7 @@ import {
41
42
// We optionally annotate the express Request with a rawBody field.
42
43
// Express leaves the Express namespace open to allow merging of new fields.
43
44
declare global {
45
+ // eslint-disable-next-line @typescript-eslint/no-namespace
44
46
namespace Express {
45
47
export interface Request {
46
48
rawBody ?: Buffer ;
@@ -63,7 +65,7 @@ let latestRes: express.Response | null = null;
63
65
* @param err Error from function execution.
64
66
* @param res Express response object.
65
67
*/
66
- // tslint: disable-next-line:no -any
68
+ // eslint- disable-next-line @typescript-eslint/no-explicit -any
67
69
function sendResponse ( result : any , err : Error | null , res : express . Response ) {
68
70
if ( err ) {
69
71
res . set ( FUNCTION_STATUS_HEADER_FIELD , 'error' ) ;
@@ -131,7 +133,7 @@ function wrapCloudEventFunction(
131
133
) : HttpFunction {
132
134
return ( req : express . Request , res : express . Response ) => {
133
135
const callback = process . domain . bind (
134
- // tslint: disable-next-line:no -any
136
+ // eslint- disable-next-line @typescript-eslint/no-explicit -any
135
137
( err : Error | null , result : any ) => {
136
138
if ( res . locals . functionExecutionFinished ) {
137
139
console . log ( 'Ignoring extra callback call' ) ;
@@ -184,7 +186,7 @@ function wrapEventFunction(
184
186
return ( req : express . Request , res : express . Response ) => {
185
187
const event = req . body ;
186
188
const callback = process . domain . bind (
187
- // tslint: disable-next-line:no -any
189
+ // eslint- disable-next-line @typescript-eslint/no-explicit -any
188
190
( err : Error | null , result : any ) => {
189
191
if ( res . locals . functionExecutionFinished ) {
190
192
console . log ( 'Ignoring extra callback call' ) ;
@@ -251,6 +253,7 @@ function registerFunctionRoutes(
251
253
if ( functionSignatureType === SignatureType . HTTP ) {
252
254
app . use ( '/favicon.ico|/robots.txt' , ( req , res , next ) => {
253
255
res . sendStatus ( 404 ) ;
256
+ next ( ) ;
254
257
} ) ;
255
258
256
259
app . use ( '/*' , ( req , res , next ) => {
@@ -266,17 +269,17 @@ function registerFunctionRoutes(
266
269
} ) ;
267
270
} else if ( functionSignatureType === SignatureType . EVENT ) {
268
271
app . post ( '/*' , ( req , res , next ) => {
269
- const wrappedUserFunction = wrapEventFunction ( userFunction as
270
- | EventFunction
271
- | EventFunctionWithCallback ) ;
272
+ const wrappedUserFunction = wrapEventFunction (
273
+ userFunction as EventFunction | EventFunctionWithCallback
274
+ ) ;
272
275
const handler = makeHttpHandler ( wrappedUserFunction ) ;
273
276
handler ( req , res , next ) ;
274
277
} ) ;
275
278
} else {
276
279
app . post ( '/*' , ( req , res , next ) => {
277
- const wrappedUserFunction = wrapCloudEventFunction ( userFunction as
278
- | CloudEventFunction
279
- | CloudEventFunctionWithCallback ) ;
280
+ const wrappedUserFunction = wrapCloudEventFunction (
281
+ userFunction as CloudEventFunction | CloudEventFunctionWithCallback
282
+ ) ;
280
283
const handler = makeHttpHandler ( wrappedUserFunction ) ;
281
284
handler ( req , res , next ) ;
282
285
} ) ;
@@ -318,6 +321,7 @@ export class ErrorHandler {
318
321
process . on ( signal as NodeJS . Signals , ( ) => {
319
322
console . log ( `Received ${ signal } ` ) ;
320
323
this . server . close ( ( ) => {
324
+ // eslint-disable-next-line no-process-exit
321
325
process . exit ( ) ;
322
326
} ) ;
323
327
} ) ;
0 commit comments