Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dist
coverage
playwright-report
test-results
uploads

# Git
.git
Expand All @@ -27,4 +28,4 @@ test-results

# Logs
*.log
npm-debug.log*
npm-debug.log*
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ API_PORT=3001
AUTH_TRUST_PROXY=false
# false for localhost/current HTTP VM; true when HTTPS is configured.
AUTH_COOKIE_SECURE=false
# Optional absolute directory for persisted recipe images (default: uploads/ at project root).
# UPLOAD_DIR=/var/lib/recipe-platform/uploads
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ on:
jobs:
quality:
runs-on: [self-hosted, linux, x64, t31-project2-ci]
env:
DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
steps:
- uses: actions/checkout@v4
- name: Require test database connection
run: |
if [ -z "$DATABASE_URL" ]; then
echo "::error::Set the TEST_DATABASE_URL Actions secret to a dedicated PostgreSQL test database accessible from this runner."
exit 1
fi
- uses: actions/setup-node@v4
with: { node-version-file: .node-version, cache: npm }
- run: npm ci
Expand All @@ -17,6 +25,10 @@ jobs:
run: npm run db:check
- name: Lint, typecheck, test and build
run: npm run check
- name: Test database constraints and migrations
run: npm run test:db
- name: Test recipe API and image storage
run: npm run test:api
- run: npx playwright install chromium
- run: npm run test:e2e
- name: Save tested release
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage/
playwright-report/
test-results/
*.tsbuildinfo
uploads/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ Frontend blir tilgjengelig på:
http://127.0.0.1:5173/project2/
```

Oppskriftsvisningen kan også kjøres med frontend alene:
Frontend-serveren kan også startes separat (API og PostgreSQL kreves for data):

```bash
npm run dev:web
```

Innlogging og registrering krever imidlertid både API-et og PostgreSQL.
Oppskriftsvisning, cookbook og innlogging krever både API-et og PostgreSQL. Se [frontend integration checklist](docs/frontend-integration.md).

Ikke legg `.env`, passord, tokens eller andre hemmeligheter i Git.

## Authentication

Registration, login and logout use GraphQL and PostgreSQL. Both the API and database must be running; recipe browsing still uses mock data. Configure DATABASE_URL in .env and run `npm run db:migrate` before starting the API. User and session creation run in one transaction, so a failed session insert rolls back the new user.
Registration, login and logout use GraphQL and PostgreSQL. Both the API and database must be running; recipe browsing and CRUD also use the API. Configure DATABASE_URL in .env and run `npm run db:migrate` before starting the API. User and session creation run in one transaction, so a failed session insert rolls back the new user.

Sessions use a host-only HttpOnly cookie (`t31_project2_session`, SameSite=Lax, Path=/, seven-day lifetime). GraphQL context resolves the user from the cookie. Tokens are not returned to frontend JavaScript or stored in localStorage. Logout revokes the server session and clears the cookie. Temporary API failures preserve the cookie for retry. Existing users must log in again after this migration.

Expand Down
17 changes: 17 additions & 0 deletions apps/api/migrations/0004_uploaded_images.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE "project2"."uploaded_images" (
"filename" text PRIMARY KEY NOT NULL,
"owner_id" uuid,
"byte_size" integer NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "uploaded_images_size_valid" CHECK ("project2"."uploaded_images"."byte_size" >= 0)
);
--> statement-breakpoint
ALTER TABLE "project2"."uploaded_images" ADD CONSTRAINT "uploaded_images_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "project2"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "uploaded_images_owner_idx" ON "project2"."uploaded_images" USING btree ("owner_id");
--> statement-breakpoint
INSERT INTO "project2"."uploaded_images" (filename, owner_id, byte_size, created_at)
SELECT DISTINCT ON (image_url) substring(image_url from 10), author_id, 0, created_at
FROM "project2"."recipes"
WHERE image_url ~ '^/uploads/[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\.(jpg|png|webp)$'
ORDER BY image_url, created_at
ON CONFLICT DO NOTHING;
Loading