@told/azure-functions-server
v1.9.16
Published
Azure Functions Server
Downloads
146
Readme
Azure Functions Server
Cli tool and Base Code for Node Azure Functions with Typescript
Usage
npm install @told/azure-functions-server --save
// Add this to package.json > scripts:
// "afs": ".\\node_modules\\.bin\\afs -w",
npm run afs
Source Project Structure
- src-server contains azure function entrances
- example-function-get-blob.ts
- An example of generating a random uuid for a user and giving them a azure storage blob with sas write access
- example-function-resource.ts
- An example of serving files from the deployment/resources folder
- __dirname is relative to the azure function runtime path (not the original source file)
- example-function-get-blob.ts
- src contains common code for app models and business logic
- app models and business logic can be tested with karma + jasmine
- app models and business logic can be used to do client side processing (that can be verified by server-side processing if needed)
- resources
- contains the BOILERPLATE for a azure function
- test.js is used for local testing which simulates an azure function call
- index.js is the entrance for azure which calls build.js
- build.js (generated by webpack in the cli)
- build.source.js is the source file used for webpack to generate the deployment/FUNCTION/build.js
- contains the BOILERPLATE for a azure function
- .deployment directs azure git deployment to use the "deployment" folder as root
- (generated) deployment contains the server-side deployment code
- a clone of lib code
- a clone of package.json with dev-dependencies removed
- a generated function entry point for each entry point in src-server
Webpack for Node Azure Functions
The cli tool manually calls webpack after moving everything into the deployment folder.
See src-cli/run-webpack.ts to see actual call in typescript.
At time of writing, the configuration settings are:
entry: {
// './EXAMPLE.webpack.js': './EXAMPLE.js',
},
output: {
path: './',
filename: '[name]'
},
target: 'node',
node: {
__filename: false,
__dirname: false,
}
Webpack Performance
The chart below shows an example of the difference between using webpack and removing node_modules or just using node_modules.
The tested function used the azure-storage npm package to create a random blob sas url.
Webpack was able to package the azure-storage without a problem and cold start performance increased from an unnacceptable time of 80 secs to an acceptable 3 sec cold start (25x increase).
Keep Alive Timer Trigger Function
Futher improvements can be gained by using a timer function (at around 4 mins) to keep the functions from going cold.
Although this will help for services that have sporadic requests, it does not help with services that require scaling up quickly as scaling to another instance still requires a cold start.