From 85e9f19a633a0906546e22a4a2dee714afae4e78 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 17 Aug 2019 15:25:19 -0400 Subject: [PATCH] Provide TypeORM config in code --- .gitignore | 1 + lib/index.ts | 29 +++++++++++++++++++++++++++-- ormconfig.json | 24 ------------------------ 3 files changed, 28 insertions(+), 26 deletions(-) delete mode 100644 ormconfig.json diff --git a/.gitignore b/.gitignore index 4efbbea..195e78d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ out/ *.pem *.db *.swp +.idea/ diff --git a/lib/index.ts b/lib/index.ts index 638056e..43e7569 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -10,6 +10,8 @@ import validateHttpSig from "./activitypub/middleware/http-signature"; //import sqlite3 from "sqlite3"; import "reflect-metadata"; import { createConnection} from "typeorm"; +import { promises as fs } from "fs"; +import * as path from "path"; //createConnection().then(async connection => { @@ -47,10 +49,33 @@ async function generate(): Promise { (async () => { const app = express(); - app.use(morgan("dev")) + app.use(morgan("dev")); app.use(bodyParser.json({ type: "application/activity+json" })); - const connection = await createConnection(); + const connection = await createConnection({ + "type": "postgres", + "host": "localhost", + "port": 5432, + "username": "blog", + "password": "blog", + "database": "blog", + "synchronize": true, + "logging": true, + "entities": [ + path.join(__dirname, "entity/**/*.{ts,js}") + ], + "migrations": [ + path.join(__dirname, "migration/**/*.{ts,js}") + ], + "subscribers": [ + path.join(__dirname, "subscriber/**/*.{ts,js}") + ], + "cli": { + "entitiesDir": "lib/entity", + "migrationsDir": "lib/migration", + "subscribersDir": "lib/subscriber" + } + }); const posts = await generate(); diff --git a/ormconfig.json b/ormconfig.json deleted file mode 100644 index 016ae5e..0000000 --- a/ormconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "type": "postgres", - "host": "localhost", - "port": 5432, - "username": "blog", - "password": "blog", - "database": "blog", - "synchronize": true, - "logging": true, - "entities": [ - "built/entity/**/*.js" - ], - "migrations": [ - "built/migration/**/*.js" - ], - "subscribers": [ - "built/subscriber/**/*.js" - ], - "cli": { - "entitiesDir": "lib/entity", - "migrationsDir": "lib/migration", - "subscribersDir": "lib/subscriber" - } -}