Skip to content

Commit a71f405

Browse files
refactor: move the bin entrypoint out of index.ts (GoogleCloudPlatform#377)
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.
1 parent 7617801 commit a71f405

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"build/src/**/*.d.ts"
3535
],
3636
"bin": {
37-
"functions-framework": "./build/src/index.js",
38-
"functions-framework-nodejs": "./build/src/index.js"
37+
"functions-framework": "./build/src/main.js",
38+
"functions-framework-nodejs": "./build/src/main.js"
3939
},
4040
"author": "Google Inc.",
4141
"license": "Apache-2.0",

src/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env node
2-
31
// Copyright 2019 Google LLC
42
//
53
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +12,6 @@
1412
// See the License for the specific language governing permissions and
1513
// limitations under the License.
1614

17-
import {main} from './main';
18-
1915
/**
2016
* @public
2117
*/
@@ -25,6 +21,3 @@ export * from './functions';
2521
* @public
2622
*/
2723
export {http, cloudevent} from './function_registry';
28-
29-
// Call the main method to load the user code and start the http server.
30-
main();

src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env node
2+
13
// Copyright 2019 Google LLC
24
//
35
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -64,3 +66,6 @@ export const main = async () => {
6466
throw e;
6567
}
6668
};
69+
70+
// Call the main method to load the user code and start the http server.
71+
main();

0 commit comments

Comments
 (0)