The 121-Service is the backend where 121-programs can be created and monitored, etc.
See instructions to get started in the main README
.
- Access the Swagger UI via: http://localhost:3000/docs/
- API-specification in JSON-format via: http://localhost:3000/docs-json
- A graph will be generated when run in 'development' mode at
module-dependencies.md
. It can be viewed with https://mermaid.live/ or the VSCode-extension: Markdown Preview Mermaid Support
Make sure to update any dependencies from within the Docker-container, with:
docker compose exec 121-service npm install --save
This service uses TypeORM with a PostgreSQL database.
To create the database initially, you have to run a command once:
docker exex -it 121-service npm run setup
This will add 1 admin
-user. It will only do so, if no existing users are found. The password and e-mail for this user can be customized in centralized services/.env
file.
To seed the database with more data (e.g. programs) additional seed-scripts can be run manually.
NOTE: These seed-scripts delete all existing data. They cannot be run on production; When run locally or on test-environment, you are prompted with 'Are you sure? (y/n)
'.
See services/121-service/package.json
for exact commands per program.
The same can be achieved by using the api/reset
endpoint from the Swagger UI.
- If you have no users in your database yet, start with running one of the reset/seed-scripts above.
- If you have already created the above user earlier, make a request:
POST /users/login
'. Change the example-value where necessary, and execute. - The 121-service will respond with a (httpOnly-)Cookie containing the users's details and permissions, the cookie will be used automatically on subsequent requests.
- This will give access to each API-endpoint for which a
Permission
is specified and a matchingPermission
is present in the users' token/cookie.
For FSP-specific instructions, see the README.md in each individual FSP-folder, e.g. for Intersolve
To run the Unit-tests: (replace :all
with :watch
to run during development)
docker exec 121-service npm run test:unit:all
To run the API/Integration tests: (replace :all
with :watch
to run during development)
docker exec 121-service npm run test:e2e:all
To run a single test suite, amend the name of the test file, for example:
docker exec 121-service npm run test:e2e:all update-program.test.ts
To enter the 121-service in the terminal use: (Or use the "Exec"-tab inside Docker Desktop)
docker exec -it 121-service /bin/sh
To start a debugger using Chrome, follow these steps:
- Add port mapping to the docker-compose.development.yml so that internal port 9229 is mapped to external port 9229. Note that all port settings from the main file are overridden.
- In the start:dev script in the package.json of the 121-service, add =0.0.0.0 to the -- inspect flag, so it becomes --inspect=0.0.0.0
- Start the services with npm run start:services.
- In the code of the 121 Service where you want to break, add a line with debugger;
- Check if the application indeed started on a debugger address 0.0.0.0 with npm run logs:services 121-services, and see something like: Debugger listening on ws://0.0.0.0:9229 02384d3e-4d1f-40ef-b8d5-be3da792fe71
- Open the Swagger Docs in the Chrome Web Browser: http://localhost:3000/docs/
- Open the Inspector in Chrome with CTRL-SHIFT-I or right mouse click and select Inspect. Now there should be a green hexagon on the top left of the Inspector window.
- Click the green hexagon item in the top left of the Inspector window (Open dedicated DevTools for Node.js).
- This opens a new window called DevTools. Leave it open.
- In the logs of the 121 Service it should say: Debugger attached.
- Use Swagger API to call the endpoint that will run into the code where you set the debugger; statement (see point 4 above.)
- The DevTools window now should show your code and Debugger functionality so you can watch variables, step over code, etc.
- In the left margin of the code, you can also right mouse click and for example select: continue to here.
- If you want to set the theme to dark, go to Settings in DevTools and under Preferences you have Theme, there select Dark. For more info: https://stackoverflow.com/questions/20777454/google-chrome-customize-developer-tools-theme-color-schema
To start the debugger from Visual Studio Code, follow these steps:
- Probably some steps from above, starting debugger in Chrome, are also needed here, but not sure which. Maybe items 1, and 2.
- The contents of launch.json in the root folder of the repository enable the possibility to attach the Debugger in Visual Studio Code to the Node.js process running in the 121-service Docker container.
- Start the services with npm run start:services, probably need to do this from a Terminal inside Visual Studio Code.
- Open the Run and Debug section in Visual Studio Code by clicking the play arrow with bug icon in the left vertical bar of icons.
- Press the green play icon left besides the "Docker: Attach to Node" text which is selected by default in the dropdown. This attaches the Debugger.
- Now you can for example set a breakpoint in your code by right mouse clicking to the left of the line number and select Add breakpoint.
Released under the Apache 2.0 License. See LICENSE.