Skip to content

Commit

Permalink
refactor: move the bin entrypoint out of index.ts (#377)
Browse files Browse the repository at this point in the history
This commit moves the call to bootstrap the express server out of
index.ts. This is an important change now that we have declarative
function signatures because we expect developers to include an import
statement for the functions-framework. Before this change doing so would
have automatically started the express http server which makes is hard
to do things like write unit tests.
  • Loading branch information
matthewrobertson committed Oct 29, 2021
1 parent 7617801 commit a71f405
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -34,8 +34,8 @@
"build/src/**/*.d.ts"
],
"bin": {
"functions-framework": "./build/src/index.js",
"functions-framework-nodejs": "./build/src/index.js"
"functions-framework": "./build/src/main.js",
"functions-framework-nodejs": "./build/src/main.js"
},
"author": "Google Inc.",
"license": "Apache-2.0",
Expand Down
7 changes: 0 additions & 7 deletions src/index.ts
@@ -1,5 +1,3 @@
#!/usr/bin/env node

// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {main} from './main';

/**
* @public
*/
Expand All @@ -25,6 +21,3 @@ export * from './functions';
* @public
*/
export {http, cloudevent} from './function_registry';

// Call the main method to load the user code and start the http server.
main();
5 changes: 5 additions & 0 deletions src/main.ts
@@ -1,3 +1,5 @@
#!/usr/bin/env node

// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -64,3 +66,6 @@ export const main = async () => {
throw e;
}
};

// Call the main method to load the user code and start the http server.
main();

0 comments on commit a71f405

Please sign in to comment.