From 662a6745f2091300d89020621cb2d72c6e195742 Mon Sep 17 00:00:00 2001 From: Justin McLellan Date: Mon, 6 Apr 2026 14:14:25 -0500 Subject: [PATCH] interceptor and better configs --- apps/api/drizzle.config.ts | 9 +++------ apps/api/src/db/index.ts | 4 +++- apps/api/src/main.ts | 1 + apps/web/server.ts | 2 -- apps/web/src/app/api.interceptor.ts | 14 ++++++++++++++ apps/web/src/app/app.component.html | 3 +-- apps/web/src/app/app.config.ts | 5 +++-- apps/web/src/index.html | 2 +- 8 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 apps/web/src/app/api.interceptor.ts diff --git a/apps/api/drizzle.config.ts b/apps/api/drizzle.config.ts index d60c8d5..c149079 100644 --- a/apps/api/drizzle.config.ts +++ b/apps/api/drizzle.config.ts @@ -1,13 +1,10 @@ import { defineConfig } from 'drizzle-kit'; -import { resolve } from 'path'; - -const apiDir = __dirname; export default defineConfig({ - schema: resolve(apiDir, 'src/db/schema.ts'), - out: resolve(apiDir, 'drizzle'), + schema: './apps/api/src/db/schema.ts', + out: './apps/api/drizzle', dialect: 'sqlite', dbCredentials: { - url: resolve(apiDir, 'sqlite.db'), + url: './apps/api/sqlite.db', }, }); diff --git a/apps/api/src/db/index.ts b/apps/api/src/db/index.ts index f4c7246..2715145 100644 --- a/apps/api/src/db/index.ts +++ b/apps/api/src/db/index.ts @@ -1,6 +1,8 @@ import Database from 'better-sqlite3'; import { drizzle } from 'drizzle-orm/better-sqlite3'; +import { join } from 'path'; import * as schema from './schema'; -const sqlite = new Database('sqlite.db'); +const dbPath = join(process.cwd(), 'apps/api/sqlite.db'); +const sqlite = new Database(dbPath); export const db = drizzle(sqlite, { schema }); diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 0d44603..7aceaa7 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -9,6 +9,7 @@ import { AppModule } from './app/app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); + app.enableCors(); const globalPrefix = 'api'; app.setGlobalPrefix(globalPrefix); const port = process.env.PORT || 3000; diff --git a/apps/web/server.ts b/apps/web/server.ts index 854a77b..a42c998 100644 --- a/apps/web/server.ts +++ b/apps/web/server.ts @@ -18,8 +18,6 @@ export function app (): express.Express { server.set('view engine', 'html'); server.set('views', browserDistFolder); - // Example Express Rest API endpoints - // server.get('/api/**', (req, res) => { }); // Serve static files from /browser server.get( '**', diff --git a/apps/web/src/app/api.interceptor.ts b/apps/web/src/app/api.interceptor.ts new file mode 100644 index 0000000..cae6349 --- /dev/null +++ b/apps/web/src/app/api.interceptor.ts @@ -0,0 +1,14 @@ +import { HttpInterceptorFn } from '@angular/common/http'; + +const API_BASE = 'http://localhost:3000'; + +export const apiInterceptor: HttpInterceptorFn = (req, next) => { + + if (req.url.startsWith('/api')) { + + return next(req.clone({ url: `${API_BASE}${req.url}` })); + + } + return next(req); + +}; diff --git a/apps/web/src/app/app.component.html b/apps/web/src/app/app.component.html index 2373f7f..f2db43e 100644 --- a/apps/web/src/app/app.component.html +++ b/apps/web/src/app/app.component.html @@ -1,3 +1,2 @@ -

Property Search

- +

Property Search

diff --git a/apps/web/src/app/app.config.ts b/apps/web/src/app/app.config.ts index fe1b8eb..836f5b0 100644 --- a/apps/web/src/app/app.config.ts +++ b/apps/web/src/app/app.config.ts @@ -1,4 +1,4 @@ -import { provideHttpClient, withFetch } from '@angular/common/http'; +import { provideHttpClient, withFetch, withInterceptors } from '@angular/common/http'; import { ApplicationConfig, provideZonelessChangeDetection } from '@angular/core'; import { provideClientHydration } from '@angular/platform-browser'; import { @@ -8,12 +8,13 @@ import { withRouterConfig, withViewTransitions, } from '@angular/router'; +import { apiInterceptor } from './api.interceptor'; import { appRoutes } from './app.routes'; export const appConfig: ApplicationConfig = { providers: [ provideClientHydration(), - provideHttpClient(withFetch()), + provideHttpClient(withFetch(), withInterceptors([apiInterceptor])), provideZonelessChangeDetection(), provideRouter( appRoutes, diff --git a/apps/web/src/index.html b/apps/web/src/index.html index b2bf598..47f5e17 100644 --- a/apps/web/src/index.html +++ b/apps/web/src/index.html @@ -2,7 +2,7 @@ - angular-task + Crexi Typescript Task