ソースを参照

Add DB connection. TG-5 #in-progress

Tati 7 年 前
コミット
e2786924e1
4 ファイル変更24 行追加4 行削除
  1. 3 2
      .gitignore
  2. 1 0
      ktchn/package.json
  3. 14 1
      ktchn/src/server.ts
  4. 6 1
      package.json

+ 3 - 2
.gitignore

@@ -1,4 +1,5 @@
 node_modules
-kitchn/node_modules
+ktchn/node_modules
 package-lock.json
-lib
+lib
+ktchn/.env

+ 1 - 0
ktchn/package.json

@@ -21,6 +21,7 @@
     "cheerio": "^1.0.0-rc.2",
     "cookie-parser": "~1.4.3",
     "debug": "~2.6.9",
+    "dotenv": "^6.2.0",
     "express": "~4.16.0",
     "morgan": "~1.9.0",
     "nano": "^7.1.0",

+ 14 - 1
ktchn/src/server.ts

@@ -3,20 +3,33 @@ import cookieParser from "cookie-parser";
 import * as bodyParser from "body-parser";
 import logger from "morgan";
 import express from "express";
-
 import rootRouter from "./routes/root";
 import recipeRouter from "./recipes/routes";
+import nano from 'nano';
+import dotenv from 'dotenv';
 
 class App {
   public express: express.Application;
+  public db: nano.DatabaseScope;
 
   constructor() {
+    this.dotENV();
     this.express = express();
     this.middleware();
     this.routes();
     this.launchConf();
+    this.db = this.couchDB();
+  }
+
+  private dotENV(): void {
+    dotenv.config();
   }
 
+  private couchDB(): nano.DatabaseScope {
+    let db = nano(process.env.COUCHDB_URL || 'http://localhost:5984/').db;
+    let recipes = db.use('recipes');
+    return db;
+  }
   private routes(): void {
     this.express.use("/recipes", recipeRouter);
     this.express.use("/", rootRouter);

+ 6 - 1
package.json

@@ -9,8 +9,13 @@
   "author": "",
   "license": "ISC",
   "dependencies": {
+    "@types/dotenv": "^6.1.0",
+    "@types/sqlite3": "^3.1.3",
+    "dotenv": "^6.2.0",
     "express": "^4.16.4",
-    "ramda": "^0.26.1"
+    "nano": "^8.0.0",
+    "ramda": "^0.26.1",
+    "sqlite3": "^4.0.6"
   },
   "devDependencies": {
     "@types/ramda": "github:types/npm-ramda#dist"