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
9 changes: 3 additions & 6 deletions apps/api/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -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',
},
});
4 changes: 3 additions & 1 deletion apps/api/src/db/index.ts
Original file line number Diff line number Diff line change
@@ -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 });
1 change: 1 addition & 0 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions apps/web/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'**',
Expand Down
14 changes: 14 additions & 0 deletions apps/web/src/app/api.interceptor.ts
Original file line number Diff line number Diff line change
@@ -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);

};
3 changes: 1 addition & 2 deletions apps/web/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<h1>Property Search</h1>
<router-outlet />
<h1 class="text-3xl font-bold mb-6">Property Search</h1>
<router-outlet />
5 changes: 3 additions & 2 deletions apps/web/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>angular-task</title>
<title>Crexi Typescript Task</title>
<base href="/" />
<meta content="width=device-width, initial-scale=1" name="viewport" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
Expand Down
Loading