chore: configure angular and postgres foundation
This commit is contained in:
@@ -13,18 +13,26 @@
|
|||||||
"start:debug": "nest start --debug --watch",
|
"start:debug": "nest start --debug --watch",
|
||||||
"start:prod": "node dist/main",
|
"start:prod": "node dist/main",
|
||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||||
"test": "jest",
|
"test": "jest --detectOpenHandles",
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
"test:cov": "jest --coverage",
|
"test:cov": "jest --coverage",
|
||||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
"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": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^11.0.1",
|
"@nestjs/common": "^11.0.1",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/platform-express": "^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",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1"
|
"rxjs": "^7.8.1",
|
||||||
|
"typeorm": "^1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
|
import { DatabaseModule } from './database/database.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [],
|
imports: [DatabaseModule],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
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": {
|
"serve": {
|
||||||
"builder": "@angular/build:dev-server",
|
"builder": "@angular/build:dev-server",
|
||||||
|
"options": {
|
||||||
|
"proxyConfig": "proxy.conf.json"
|
||||||
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"buildTarget": "web:build:production"
|
"buildTarget": "web:build:production"
|
||||||
|
|||||||
@@ -11,22 +11,22 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "npm@11.12.1",
|
"packageManager": "npm@11.12.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/common": "^21.2.0",
|
"@angular/common": "22.0.8",
|
||||||
"@angular/compiler": "^21.2.0",
|
"@angular/compiler": "22.0.8",
|
||||||
"@angular/core": "^21.2.0",
|
"@angular/core": "22.0.8",
|
||||||
"@angular/forms": "^21.2.0",
|
"@angular/forms": "22.0.8",
|
||||||
"@angular/platform-browser": "^21.2.0",
|
"@angular/platform-browser": "22.0.8",
|
||||||
"@angular/router": "^21.2.0",
|
"@angular/router": "22.0.8",
|
||||||
"rxjs": "~7.8.0",
|
"rxjs": "~7.8.0",
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular/build": "^21.2.6",
|
"@angular/build": "22.0.9",
|
||||||
"@angular/cli": "^21.2.6",
|
"@angular/cli": "22.0.9",
|
||||||
"@angular/compiler-cli": "^21.2.0",
|
"@angular/compiler-cli": "22.0.8",
|
||||||
"jsdom": "^28.0.0",
|
"jsdom": "^28.0.0",
|
||||||
"prettier": "^3.8.1",
|
"prettier": "^3.8.1",
|
||||||
"typescript": "~5.9.2",
|
"typescript": "6.0.3",
|
||||||
"vitest": "^4.0.8"
|
"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
|
||||||
|
}
|
||||||
|
}
|
||||||
7308
package-lock.json
generated
7308
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -12,7 +12,10 @@
|
|||||||
"build:web": "npm run build --workspace=@ashen-realms/web",
|
"build:web": "npm run build --workspace=@ashen-realms/web",
|
||||||
"build:api": "npm run build --workspace=@ashen-realms/api",
|
"build:api": "npm run build --workspace=@ashen-realms/api",
|
||||||
"build": "npm run build:web && npm run build:api",
|
"build": "npm run build:web && npm run build:api",
|
||||||
"test": "npm run test --workspaces --if-present"
|
"test": "npm run test --workspaces --if-present",
|
||||||
|
"db:migrate": "npm run typeorm --workspace=@ashen-realms/api -- migration:run -d src/database/data-source.ts",
|
||||||
|
"db:revert": "npm run typeorm --workspace=@ashen-realms/api -- migration:revert -d src/database/data-source.ts",
|
||||||
|
"db:seed": "npm run seed --workspace=@ashen-realms/api"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"apps/*",
|
"apps/*",
|
||||||
@@ -26,5 +29,10 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"private": "true"
|
"private": "true",
|
||||||
|
"devDependencies": {
|
||||||
|
"caniuse-lite": "^1.0.30001809",
|
||||||
|
"css-tree": "^3.2.1",
|
||||||
|
"ts-node": "^10.9.2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user