- Node 12
- Azure Functions CLI v3
- The Azure CLI
This project includes a dev container, with the prerequisites installed.
Copy the contents of template.settings.json
to a file in the root folder called local.settings.json
. This is where you will keep all the settings used for running the app locally. If you are running in a dev container, remember to replace all references to localhost
in your settings with host.docker.internal
You'll need a MongoDB to use to store data:
Follow the steps in Connect a MongoDB application to Azure Cosmos DB to get the connection string.
Follow the Install the emulator instructions to install the emulator and obtain the connection string. Start the emulator using C:\Program Files\Azure Cosmos DB Emulator\Microsoft.Azure.Cosmos.Emulator.exe /EnableMongoDbEndpoint=3.6
Instructions for hosting your own MongoDB isntance can be found in Install MongoDB.
Now update the mongo_connection_string
setting in your local.settings.json
file with the connection string for your chosen MongoDB host.
Connect to your MongoDB instance using the Azure portal, or a client application such as robo3t or mongo shell, and create a database called newcastle
and a collection called audits
.
Start by opening a terminal and running npm install
.
You can run the code by running func host start
in the terminal or by using Visual Studio Code:
The .vscode directory contains all the tasks you need to run and debug the code. You can press F5 to run the application and debug it, as described in Debug functions locally.
Try it out by doing an HTPP POST to http://localhost:7072/api/auditrecord
with the following body:
{
"resource": {
"id": "resourceid",
"operation": "resourceoperation",
"type": "resourcetype"
},
"sourceSystemName": "sourcesystem"
}
If your settings and MongoDB instance is configured correctly, you should receive a 201 response. The audits
collection in your db should now contain a new record.
This project contains unit and integration tests written using Mocha. You can run the code using npm by running npm test
in the terminal. You can also use the Mocha Test Explorer extension for Visual Studio Code to run the tests.
The project has been configured to generate test coverage reports, using the mocha provider for Istanbul. To generate the report, run the following script:
npm install
npm run build
npm run cover
If all tests passes, a folder called .coverage
wil be generated. Open the index.html
to view the report.
This project is configured to use ESLint for linting. Run the liniting from the terminal using npm run lint
, or using the 'lint whole folder' task for the ESLint extension for Visual Studio Code.
To publish this code to Azure and obtain a public URL using Visual Studio Code, follow the instructions here.
To significantly reduce the size of the deployed package, run npm run build:production
before publishing your app.
If your function app already exists, you can use the functions CLI to publish using the command func azure functionapp publish {functionappname}
as described in Publish to Azure.