This is the backend-application for a PoC-software to demo eReceipts. The software as a whole focuses to showcase the different possibilities eReceipts offer to the eReceipt-recipient / buyer.
The frontend-application for this software is found in another repository located here by @JGynther.
The software follows the princibles drafted for eReceipts by Finnish State Treasury. These princibles can be found in this publication called eKuitin Sääntökirja - Minimiedellytykset eKuittidatan välittämiseen.
Read documentation.md for more information about the backend structure (in finnish)
Read api-documentation for more information about API routes provided by this backend
- git clone / git pull
- yarn install
- yarn run dev
- yarn run build
- yarn run start
- Create a Microsoft Azure account
- Create a resource group inside the account
- Create two Azure Cosmos DB accounts under the created resource group, name them **-dev and **-prod
- Create a .env file in project root and update it with URI and PRIMARY KEY values from both Cosmos DB accounts.
How to create Azure account, resource group and Cosmos DB account: link
There is no need to create databases or tables. This backend-software will initialize them on startup.
- (Optional) Update the PORT value to .env file, default is 8080
- (Optional) Update the FRONTURI value to .env file, default is http://localhost:3000
- Update SECRET value to .env file, it is used for token creation when user logs in, can be any string value
PORT=""
DEV_DB_URI=""
DEV_DB_SECRET_KEY=""
PROD_DB_URI=""
PROD_DB_SECRET_KEY=""
SECRET=""
FRONTURI=""
yarn run lint
(optional) download eslint realtime error checker for vscode: link
Run requests from src/requests/--.rest
(optional) download REST client for vscode link
- Run GET request inside given .rest file and copy the value of "id" from response
- Replace the @idVariable value in the same .rest file with the copied id value
- Run requests in the .rest file which use {{idVariable}}
- Run POST request inside login.rest and copy the value of "token" from response.
- Replace the @tokenVariable value inside receipt.rest request with the copied token value
- Now run requests inside receipt.rest which use {{tokenVariable}}
Make sure to change the json file accordingly in POST request when creating a new receipt, program will throw error if eAddresses do not match
Cors policies are set differently for public router and other routers These differences can be easily tested from any browser with following methods
- Open any website (but not backend or frontend address)
- Press F12 to open devtools
- Open console tab
- Input: fetch('http://localhost:8080/api/users')
This will result in error because cors policy restricts connections from other urls than frontend or backend
- Input: fetch('http://localhost:8080/api/public/receipts')
This will not produce an error and instead will return a Promise with "status: 200". This is because public api cors policy allows all connections.