diff --git a/src/index.ts b/src/index.ts index 16386ce1..ed6ef53c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,7 +43,6 @@ const FLAG = { TARGET: 'target', SIGNATURE_TYPE: 'signature-type', // dash SOURCE: 'source', - DRY_RUN: 'dry-run', }; // Supported environment variables @@ -52,7 +51,6 @@ const ENV = { TARGET: 'FUNCTION_TARGET', SIGNATURE_TYPE: 'FUNCTION_SIGNATURE_TYPE', // underscore SOURCE: 'FUNCTION_SOURCE', - DRY_RUN: 'DRY_RUN', }; enum NodeEnv { @@ -60,7 +58,7 @@ enum NodeEnv { } const argv = minimist(process.argv, { - string: [FLAG.PORT, FLAG.TARGET, FLAG.SIGNATURE_TYPE, FLAG.DRY_RUN], + string: [FLAG.PORT, FLAG.TARGET, FLAG.SIGNATURE_TYPE], }); const CODE_LOCATION = resolve( @@ -79,7 +77,6 @@ if (SIGNATURE_TYPE === undefined) { console.error(`Function signature type must be one of 'http' or 'event'.`); process.exit(1); } -const DRY_RUN = argv[FLAG.DRY_RUN] || process.env[ENV.DRY_RUN] || false; // CLI Help Flag if (process.argv[2] === '-h' || process.argv[2] === '--help') { @@ -101,13 +98,6 @@ if (!USER_FUNCTION) { const SERVER = getServer(USER_FUNCTION!, SIGNATURE_TYPE!); const ERROR_HANDLER = new ErrorHandler(SERVER); -if (DRY_RUN) { - console.log(`Function: ${TARGET}`); - console.log(`URL: http://localhost:${PORT}/`); - console.log('Dry run successful, shutting down.'); - process.exit(0); -} - SERVER.listen(PORT, () => { ERROR_HANDLER.register(); if (process.env.NODE_ENV !== NodeEnv.PRODUCTION) { diff --git a/src/invoker.ts b/src/invoker.ts index 0b5ca420..57c2479b 100644 --- a/src/invoker.ts +++ b/src/invoker.ts @@ -480,6 +480,10 @@ function registerFunctionRoutes( functionSignatureType: SignatureType ) { if (isHttpFunction(userFunction!, functionSignatureType)) { + app.use('/favicon.ico|/robots.txt', (req, res, next) => { + res.sendStatus(404); + }); + app.use('/*', (req, res, next) => { onFinished(res, (err, res) => { res.locals.functionExecutionFinished = true; diff --git a/test/invoker.ts b/test/invoker.ts index 4664bdf0..e8659b56 100644 --- a/test/invoker.ts +++ b/test/invoker.ts @@ -29,19 +29,55 @@ describe('loading function', () => { }); describe('request to HTTP function', () => { - it('should return transformed body', () => { - const server = invoker.getServer( - (req: express.Request, res: express.Response) => { - res.send(req.body.text.toUpperCase()); - }, - invoker.SignatureType.HTTP - ); - return supertest(server) - .post('/') - .send({ text: 'hello' }) - .set('Content-Type', 'application/json') - .expect('HELLO') - .expect(200); + interface TestData { + name: string; + path: string; + text: string; + status: number; + } + + const testData: TestData[] = [ + { + name: 'empty path', + path: '/', + text: 'HELLO', + status: 200, + }, + { + name: 'simple path', + path: '/foo', + text: 'HELLO', + status: 200, + }, + { + name: 'with favicon.ico', + path: '/favicon.ico', + text: 'Not Found', + status: 404, + }, + { + name: 'with robots.txt', + path: '/robots.txt', + text: 'Not Found', + status: 404, + }, + ]; + + testData.forEach(test => { + it(`should return transformed body: ${test.name}`, () => { + const server = invoker.getServer( + (req: express.Request, res: express.Response) => { + res.send(req.body.text.toUpperCase()); + }, + invoker.SignatureType.HTTP + ); + return supertest(server) + .post(test.path) + .send({ text: 'hello' }) + .set('Content-Type', 'application/json') + .expect(test.text) + .expect(test.status); + }); }); });