mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-11-01 18:19:43 +00:00
fix(e2e): align browser harness with local stack
This commit is contained in:
1 parent
db5980c9bd
commit
cf19d23d8a
20 files changed
+267
-85
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { ApiErrorResponse, MeResponse } from '@sauci/shared';
|
||||
import { Hono } from 'hono';
|
||||
import { cors } from 'hono/cors';
|
||||
import { z } from 'zod';
|
||||
import { bearerToken, type AuthIdentity, type AuthVerifier } from './auth.js';
|
||||
import type { ApiRepository } from './db/repository.js';
|
||||
@@ -36,6 +37,7 @@ type Variables = { identity: AuthIdentity };
|
||||
export interface AppDependencies {
|
||||
auth: AuthVerifier;
|
||||
repository: ApiRepository;
|
||||
corsAllowedOrigins?: string[];
|
||||
coupleService?: CoupleService;
|
||||
packsRepository?: PacksRepository;
|
||||
answersRepository?: AnswersRepository;
|
||||
@@ -61,6 +63,15 @@ function error(code: string, message: string): ApiErrorResponse {
|
||||
export function createApp(deps: AppDependencies): Hono<{ Variables: Variables }> {
|
||||
const app = new Hono<{ Variables: Variables }>();
|
||||
|
||||
const corsAllowedOrigins = new Set(deps.corsAllowedOrigins ?? ['https://sauci.app']);
|
||||
// The public web redemption form calls the API from a distinct browser origin.
|
||||
// API authentication remains bearer-token based, so this does not grant cross-origin access to protected data.
|
||||
app.use('*', cors({
|
||||
origin: (origin) => corsAllowedOrigins.has(origin) ? origin : null,
|
||||
allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
||||
allowHeaders: ['Content-Type', 'Authorization'],
|
||||
}));
|
||||
|
||||
app.use('*', async (c, next) => {
|
||||
const startedAt = performance.now();
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user