- Node 12
- Azure functions CLI v3
- 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 here to get the connection string.
Follow the instructions here 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 here
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 patients
.
Start by opening a terminal and running npm install
.
You can run the code by running func host start
in teh terminal or by using VS Code:
The .vscode 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 here
Try it out by doing an HTPP POST to http://localhost:7071/api/patient
with the following body:
{
"firstName": "FirstName",
"lastName": "LastName",
"fullName": "FullName",
"gender": "male",
"dateOfBirth": "1908-05-23",
"postCode": "0001",
"insuranceNumber": "ins0001",
"preferredContactNumber": "01012345567"
}
If your settings and MongoDB instance is configured correctly, you should receive a 201 response. The patient
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 VS 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 VSCode.
To publish this code to Azure and obtain a public url using VSCode, 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 here.