chore: configure angular and postgres foundation
This commit is contained in:
@@ -13,18 +13,26 @@
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test": "jest --detectOpenHandles",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"typeorm": "typeorm-ts-node-commonjs",
|
||||
"seed": "ts-node src/database/seeds/seed.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@nestjs/typeorm": "^11.0.3",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.15.1",
|
||||
"dotenv": "^17.4.2",
|
||||
"pg": "^8.23.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1"
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { DatabaseModule } from './database/database.module';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
imports: [DatabaseModule],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
||||
18
apps/api/src/config/database.config.spec.ts
Normal file
18
apps/api/src/config/database.config.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createDatabaseConfig } from './database.config';
|
||||
|
||||
describe('createDatabaseConfig', () => {
|
||||
it('uses postgres and permanently disables synchronization', () => {
|
||||
expect(
|
||||
createDatabaseConfig('postgresql://test:test@localhost/test'),
|
||||
).toMatchObject({
|
||||
type: 'postgres',
|
||||
url: 'postgresql://test:test@localhost/test',
|
||||
synchronize: false,
|
||||
autoLoadEntities: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects an empty database URL', () => {
|
||||
expect(() => createDatabaseConfig('')).toThrow('DATABASE_URL is required');
|
||||
});
|
||||
});
|
||||
16
apps/api/src/config/database.config.ts
Normal file
16
apps/api/src/config/database.config.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
|
||||
export function createDatabaseConfig(
|
||||
databaseUrl: string,
|
||||
): TypeOrmModuleOptions {
|
||||
if (!databaseUrl.trim()) {
|
||||
throw new Error('DATABASE_URL is required');
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'postgres',
|
||||
url: databaseUrl,
|
||||
autoLoadEntities: true,
|
||||
synchronize: false,
|
||||
};
|
||||
}
|
||||
16
apps/api/src/database/data-source.ts
Normal file
16
apps/api/src/database/data-source.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'dotenv/config';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
|
||||
if (!databaseUrl?.trim()) {
|
||||
throw new Error('DATABASE_URL is required');
|
||||
}
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
type: 'postgres',
|
||||
url: databaseUrl,
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
migrations: [__dirname + '/migrations/*.{ts,js}'],
|
||||
synchronize: false,
|
||||
});
|
||||
12
apps/api/src/database/database.module.ts
Normal file
12
apps/api/src/database/database.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { createDatabaseConfig } from '../config/database.config';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forRootAsync({
|
||||
useFactory: () => createDatabaseConfig(process.env.DATABASE_URL ?? ''),
|
||||
}),
|
||||
],
|
||||
})
|
||||
export class DatabaseModule {}
|
||||
@@ -59,6 +59,9 @@
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular/build:dev-server",
|
||||
"options": {
|
||||
"proxyConfig": "proxy.conf.json"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "web:build:production"
|
||||
|
||||
@@ -11,22 +11,22 @@
|
||||
"private": true,
|
||||
"packageManager": "npm@11.12.1",
|
||||
"dependencies": {
|
||||
"@angular/common": "^21.2.0",
|
||||
"@angular/compiler": "^21.2.0",
|
||||
"@angular/core": "^21.2.0",
|
||||
"@angular/forms": "^21.2.0",
|
||||
"@angular/platform-browser": "^21.2.0",
|
||||
"@angular/router": "^21.2.0",
|
||||
"@angular/common": "22.0.8",
|
||||
"@angular/compiler": "22.0.8",
|
||||
"@angular/core": "22.0.8",
|
||||
"@angular/forms": "22.0.8",
|
||||
"@angular/platform-browser": "22.0.8",
|
||||
"@angular/router": "22.0.8",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/build": "^21.2.6",
|
||||
"@angular/cli": "^21.2.6",
|
||||
"@angular/compiler-cli": "^21.2.0",
|
||||
"@angular/build": "22.0.9",
|
||||
"@angular/cli": "22.0.9",
|
||||
"@angular/compiler-cli": "22.0.8",
|
||||
"jsdom": "^28.0.0",
|
||||
"prettier": "^3.8.1",
|
||||
"typescript": "~5.9.2",
|
||||
"typescript": "6.0.3",
|
||||
"vitest": "^4.0.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
apps/web/proxy.conf.json
Normal file
7
apps/web/proxy.conf.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"/api": {
|
||||
"target": "http://localhost:3000",
|
||||
"secure": false,
|
||||
"changeOrigin": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user