feat: Use authorization on the MongoDB server
This commit is contained in:
5
backend/README.md
Normal file
5
backend/README.md
Normal file
@@ -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`
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user