The mock backend is a small self-contained implementation of the gRPC api contract used for testing the frontend without having to spin up a full backend including databases. This application neither implements real api queries for scanning papers, nor does it persist any data.
Caution
Security is an afterthought and this server should never be used in production. Passwords are stored in plaintext and nothing is encrypted.
The fastest way to get started is to clone the repository and run the mock
backend using docker compose. This will start the mock backend and a gRPC web
proxy. The mock backend will be available at http://localhost:3001 and the gRPC
web proxy at http://localhost:3000.
git clone git@github.com:SE-UUlm/snowballr-mock-backend.git
cd snowballr-mock-backend
git submodule update --init
docker compose upTo start the mock backend with existing data and an admin user, you can use the mock-sample profile.
docker compose --profile mock-sample upAlternatively, you can build and run the mock backend from source.
npm i
npm run compile:proto
npm run build
npm run startTo run the mock backend with existing data and an admin user, you can use the following command:
npm run devIf connecting from a gRPC web client, the GRPC_WEB_PORT endpoint must be
targeted. If using a native client like grpcui or grpcurl, connecting to
GRPC_PORT is required.
If you're not going to use the mock backend for automated tests, but only to manually check the frontend functionality,
it's useful to have some initial data. You can start the mock backend with initial data for this purpose, whereas these
initial data must be saved in a typescript file.This file must be located in the src/data/ directory.
The data in this file is then imported and, if it is correct, saved as initial data in a "database" with which the mock
backend is started. The file is considered to be correct, if it exports an object named exampleData conforming the
ExampleData interface, e.g.
export const exampleData: ExampleData = {
users: users,
...
};A boolean variable may be enabled by setting it to either 1, yes, or true.
| Environment Variable | Default | Description |
|---|---|---|
GRPC_PORT |
3000 | The port the native server should listen on |
GRPC_WEB_PORT |
3001 | The port the gRPC web proxy should listen on |
GRPC_ALLOW_ORIGIN |
.* (allow everything) |
A regex describing what origins should be allowed by cors. |
ENABLE_DUMMY_ADMIN |
false | Whether to enable a dummy admin user |
RESPONSE_DELAY |
50 | The number of milliseconds the server's responses are delayed by. |
LOG_LEVEL |
debug |
The log level to use. One of fatal, error, warn, info, debug, trace, or silent. |
EXAMPLE_DATA_FILE |
"" | Relative path to a file inside src/data/ containing example data for the mock backend (e.g. standardData.ts) |
RANDOMNESS_SEED |
<random> | Seed used for every pseudo random value generation, (default seed is random) |
Both grpcurl and grpcui can be very helpful when getting to know the api or debugging. Install the ones you like and use them like this (replacing the address if needed):
grpcui -plaintext 127.0.0.1:3000
grpcurl -plaintext 127.0.0.1:3000 snowballr.SnowballR.IsAuthenticatedAuthorization is handled using the access and refresh tokens residing in the cookie header.
In grpcui, this should be added using the header ui by setting the value to accessToken=<token>;refreshToken=<token>.
For grpcurl, this can be achieved like this:
grpcurl -plaintext 127.0.0.1:3000 snowballr.SnowballR.CreateProject -d '{"name": "Foo"}' -H cookie:<access-token and refresh-token>