Skip to Content
DocumentationContributeSet up the backend

Set up the backend

Repository: hawconnect/hawconnect-backend . Bun, Express and Apollo, with PostgreSQL for accounts and managed content.

Install and run

Use the Bun version in .bun-version and the checked-in lockfile:

bun install --frozen-lockfile cp .env.example .env.local bun start

GraphQL then runs at http://localhost:4000/graphql. Ingesting public sources needs no university accounts, SMTP or database credentials, only outbound HTTPS. Managed content and accounts need the database.

Local environment

PORT=4000 HAWCONNECT_WEB_ORIGINS=http://localhost:3000,http://localhost:3001,http://localhost:8081 HAWCONNECT_AUTH_ORIGIN=http://localhost:4000 HAWCONNECT_WEB_ORIGIN=http://localhost:3000 HAWCONNECT_CONSOLE_ORIGIN=http://localhost:43127

Restart the backend after changing environment values.

Sign-in site locally

The sign-in site is served by the backend. Locally it runs on account.localhost:

HAWCONNECT_LOGIN_ORIGIN=http://account.localhost:4000 # at least 32 random characters, e.g. from `openssl rand -hex 32` HAWCONNECT_OIDC_SECRET_HAWCONNECT_APP=

Run bun run accounts:migrate once (and after updates). In the app, set EXPO_PUBLIC_HAWCONNECT_LOGIN_URL=http://account.localhost:4000. Chrome and Firefox resolve account.localhost themselves; Safari and emulators need another setup, such as a hosts entry.

Accounts, email and administration

These values belong only in private server configuration, never in commits or public app variables:

HAWCONNECT_ACCOUNTS_DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/DATABASE HAWCONNECT_ACCOUNT_SECRET=REPLACE_WITH_A_RANDOM_SECRET HAWCONNECT_SYNC_ENCRYPTION_KEY=REPLACE_WITH_BASE64_OF_32_RANDOM_BYTES HAWCONNECT_ADMIN_EMAILS=[email protected] HAWCONNECT_SMTP_HOST=YOUR_SMTP_HOST HAWCONNECT_SMTP_PORT=587 HAWCONNECT_SMTP_USER=YOUR_SMTP_USERNAME HAWCONNECT_SMTP_PASSWORD=YOUR_SMTP_PASSWORD HAWCONNECT_MAIL_FROM="HAWConnect <YOUR_AUTHORISED_SENDER>"

The database URL covers both accounts and campus content. Admin access needs an explicit grant; the university domain alone grants no rights.

Database

Startup does not apply migrations. Back up the target database and check its current state before changing the schema. Depending on that state, commands like these are available:

bun run migrate bun run accounts:migrate bun run admin:migrate bun run organizers:migrate bun run legal:migrate bun run clubs:migrate bun run quick-links:migrate bun run marketplace:migrate

This is not an instruction to run the whole sequence against an existing database. Keep existing sync encryption keys when you move data.

Check

bun run codegen bunx tsc --noEmit bun run lint bun test

If the GraphQL schema changes, regenerate the client in the app as well.