felanmalan-backend is an API that uses Slussen to provide data necessary for a tenant to report an error/fault in their apartment.
┌────────────┐ Λ ┌────────────┐ Λ ┌────────────┐
│ │ ╱ ╲ │ │ ╱ ╲ │ │
│ │ ╱ ╲ │ │ ╱ ╲ │ │
│ │ ╱ ╲ │ │ ╱ ╲ │ Slussen │
│ Frontend │◀───▶ json ◀─────▶│ Backend │◀────▶ json ◀─────▶(auth: jwt, │
│ │ ╲ ╱ │ │ ╲ ╱ │ 3h expire) │
│ │ ╲ ╱ │ │ ╲ ╱ │ │
│ │ ╲ ╱ │ │ ╲ ╱ │ │
└────────────┘ V └────────────┘ V └──────▲─────┘
▲ │
│ │
├────────┐ │
┌─────────┐ │ │ ▼
│Postgres │◀──┘ ▼ Λ
└─────────┘ ┌──────────┐ ╱ ╲
│ assets │ ╱ ╲
│ volume │ ╱ ╲
└──────────┘ ▕ xml ▏
╲ ╱
╲ ╱
╲ ╱
▲
│
│
│
│
┌───▼───┐
│fastapi│
└───────┘
- Node.js installed preferably using nvm
- Docker installed
- Docker Compose installed
- access to GitHub Packages
- Felanmälan uses PostgresQL that we run in Docker.
- Felanmälan uses Slussen that we run in Docker.
- You need some configuration files as described in the Config section
- Create a personal token for GitHub Packages as described above and run
docker login https://docker.pkg.github.com
We run Slussen
and the needed databases in Docker.
# omit the -d to see log output from the containers
docker-compose up -d
The rest of the project is running locally for now.
cd packages/client
npm ci
npm run dev
Visit http://localhost:3000/plats
cd packages/server
nvm use
npm i
npm run migrate:up
npm run dev
Go to http://localhost:3001/
You need to create a user in Slussen
to be able to connect to the api. This is described in Slussen's README but since we're running things from within this project here are instructions (roughly.):
First we get the password hash and salt:
curl "http://localhost:4000/auth/generate-password-hash?password=mypassword"
# {"password": "...", "salt": "..."}
Then we insert it into Slussen's database.
# Assuming you have not changed anything
PGHOST=0.0.0.0 PGPASSWORD=postgrespassword PGUSER=postgres PGDATABASE=api-db psql
# Choose a username and use the values from the first step
INSERT INTO users (username, password_hash, salt)
VALUES
(
'myusername',
'password_hash',
'password_salt'
);
At that point the last thing we need is an OAuth token from the API.
curl -XPOST -H "Content-type: application/json" -d '{"password": "mypassword", "username": "myusername"}' 'http://localhost:4000/auth/generate-token'
Default values are stored in src/config.ts
, and are overriden
by config.json
.
For example, use different Slussen user:
{
"api": {
"username": "myusername",
"password": "mypassword"
}
}
Note that to run these commands you must set a DATABASE_URL environment variable that points to the Postgres database called felanmalan-postgres
in docker-compose.yml.
- Create new migration:
npx knex migrate:make <migration_name>
- Create new seed for dev:
npx knex seed:make $(date +%s)_<name> --env dev
- Reset (recreate and seed) dev db:
npm run reset:dev