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
215 changes: 121 additions & 94 deletions README.md

Large diffs are not rendered by default.

281 changes: 279 additions & 2 deletions backend/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "tsc",
"watch": "tsc -w",
"start": "node dist/handlers/api.js",
"dev": "ts-node src/handlers/api.ts",
"dev": "ts-node src/server.ts",
"test": "jest",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix",
Expand All @@ -19,8 +19,10 @@
"dependencies": {
"@aws-sdk/client-cognito-identity-provider": "^3.400.0",
"@fastify/aws-lambda": "^4.0.0",
"@fastify/cookie": "^9.4.0",
"@fastify/cors": "^9.0.0",
"aws-jwt-verify": "^4.0.0",
"axios": "^1.10.0",
"dotenv": "^17.0.1",
"fastify": "^4.21.0",
"google-auth-library": "^9.0.0"
Expand Down
48 changes: 48 additions & 0 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { FastifyInstance, fastify } from 'fastify';
import { getConfig } from './config';
import { Logger } from './utils/logger';

// Import middleware
import { registerCors } from './middleware/cors';
import { registerAuth } from './middleware/auth';

// Import route modules
import { registerHealthRoutes } from './routes/health';
import { registerAuthRoutes } from './routes/auth';
import { registerUserRoutes } from './routes/users';

export interface AppOptions {
environment?: 'development' | 'lambda';
logger?: boolean;
}

/**
* Creates and configures the main Fastify application
* This factory can be used by both development server and Lambda handler
*/
export function createApp(options: AppOptions = {}): FastifyInstance {
const config = getConfig();
const logger = new Logger({ service: 'App' });

const app = fastify({
logger: options.logger ?? false,
});

logger.info('Creating Fastify application', {
environment: options.environment || 'unknown',
stage: config.app.stage,
});

// Register middleware in order
registerCors(app, config);
registerAuth(app, options.environment);

// Register route modules
registerHealthRoutes(app);
registerAuthRoutes(app);
registerUserRoutes(app);

logger.info('Fastify application created successfully');

return app;
}
4 changes: 3 additions & 1 deletion backend/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface AppConfig {
userPoolId: string;
clientId: string;
clientSecret: string;
domain: string;
};
};

Expand Down Expand Up @@ -64,7 +65,8 @@ function validateConfiguration(): AppConfig {
cognito: {
userPoolId: getRequiredEnvVar('COGNITO_USER_POOL_ID'),
clientId: getRequiredEnvVar('COGNITO_CLIENT_ID'),
clientSecret: getRequiredEnvVar('COGNITO_CLIENT_SECRET'),
clientSecret: getOptionalEnvVar('COGNITO_CLIENT_SECRET', ''), // Will be retrieved at runtime if empty
domain: getOptionalEnvVar('COGNITO_DOMAIN', ''),
},
},
google: {
Expand Down
Loading
Loading