diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..a8399ff --- /dev/null +++ b/backend/README.md @@ -0,0 +1,5 @@ +# Lateinicus Server +## Requirements +- a database called `lateinicus` +- a user called `backend` on the database `lateinicus` + - the role `readWrite` for the database `lateinicus` diff --git a/backend/src/main.ts b/backend/src/main.ts index dbbabf1..0293cf1 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -1,3 +1,6 @@ +import { env } from "process"; +import * as assert from "assert"; + import * as express from "express"; import * as cors from "cors"; @@ -15,13 +18,15 @@ const baseRouter = express.Router(); const authRouter = express.Router(); import { MongoClient } from "mongodb"; -const assert = require('assert'); + +const user = encodeURIComponent("backend"); +const password = encodeURIComponent(env["LATEINICUS_USER_PW"]); (async function() { - // Connection URL - const url = 'mongodb://128.1.0.2:27017/myproject'; // Database Name - const dbName = 'myproject'; + const dbName = 'lateinicus'; + // Connection URL + const url = `mongodb://${user}:${password}@128.1.0.2:27017/?authMechanism=SCRAM-SHA-1&authSource=${dbName}`; let client: MongoClient; try { @@ -30,7 +35,7 @@ const assert = require('assert'); console.log("Connected to MongoDB"); } catch (err) { console.log(err.stack); - assert(1, 2); + assert(false); } const db = client.db(dbName); diff --git a/compose.yml b/compose.yml index d931892..3171cbc 100644 --- a/compose.yml +++ b/compose.yml @@ -2,7 +2,11 @@ version: "3.6" services: db: - image: mongo:4.1.3-xenial + image: mongo:4.0.2-xenial + command: mongod --config /etc/mongo/mongod.conf + volumes: + - ./server/db/:/etc/mongo/db/:rw + - ./server/mongod.conf:/etc/mongo/mongod.conf:ro expose: - "27017" networks: @@ -11,6 +15,8 @@ services: backend: image: lateinicus/server + environment: + - LATEINICUS_USER_PW=abc123 expose: - "8080" depends_on: diff --git a/server/mongod.conf b/server/mongod.conf new file mode 100644 index 0000000..8846ab8 --- /dev/null +++ b/server/mongod.conf @@ -0,0 +1,10 @@ +storage: + engine: wiredTiger + dbPath: /etc/mongo/db/ + +security: + authorization: enabled + javascriptEnabled: false + +net: + port: 27017 \ No newline at end of file