diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index 8df7846..f495692 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
- <data-source source="LOCAL" name="myproject@localhost" uuid="6433d464-6ca0-4d7d-a023-05bd4df14dd6">
+ <data-source source="LOCAL" name="nodejs@localhost" uuid="6433d464-6ca0-4d7d-a023-05bd4df14dd6">
<driver-ref>mongo.4</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.dbschema.MongoJdbcDriver</jdbc-driver>
- <jdbc-url>mongodb://localhost:27017/myproject</jdbc-url>
+ <jdbc-url>mongodb://localhost:27017/nodejs</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
+ <driver-properties>
+ <property name="authSource" value="admin" />
+ </driver-properties>
</data-source>
</component>
</project>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..ca60690
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/.idea/nodejs-final-assignment.iml" filepath="$PROJECT_DIR$/.idea/nodejs-final-assignment.iml" />
+ </modules>
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/nodejs-final-assignment.iml b/.idea/nodejs-final-assignment.iml
new file mode 100644
index 0000000..24643cc
--- /dev/null
+++ b/.idea/nodejs-final-assignment.iml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$">
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module>
\ No newline at end of file
diff --git a/README.md b/README.md
index 3bc89d4..e15cc71 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,10 @@
[](https://classroom.github.com/a/3A9ByVp3)
+
+# Deployment
+
+Environment variables:
+| Name | Default | Description |
+| ---- | ------- | ----------- |
+| `PORT` | `3000` | The port the server will run on. |
+| `LOG_REQUESTS` | `-` | Requests to log to the console by status, `-` to invert. |
+| `DATABASE_SECRET_PATH` | `` | The path to the mongodb connection string. |
\ No newline at end of file
diff --git a/src/api/routes/auth/registerRoute.js b/src/api/routes/auth/registerRoute.js
index b71c466..14188a4 100644
--- a/src/api/routes/auth/registerRoute.js
+++ b/src/api/routes/auth/registerRoute.js
@@ -1,4 +1,4 @@
-import { User } from "#db/schemas/userSchema.js";
+import { User } from "#db/schemas/user.js";
export const registerRoute = {
route: "/auth/register",
diff --git a/src/api/routes/statusRoute.js b/src/api/routes/statusRoute.js
index f1cdb99..b9974a5 100644
--- a/src/api/routes/statusRoute.js
+++ b/src/api/routes/statusRoute.js
@@ -1,4 +1,4 @@
-import { User } from "#db/schemas/userSchema.js";
+import { User } from "#db/schemas/user.js";
export const statusRoute = {
route: "/status",
diff --git a/src/db/db.js b/src/db/db.js
index bf7ccfa..36f2105 100644
--- a/src/db/db.js
+++ b/src/db/db.js
@@ -1,13 +1,16 @@
import { connect } from "mongoose";
+import { readSecret } from "#util/secretUtils.js";
export async function initDb() {
- const connStr = "mongodb://root:Foxy1987@localhost/myproject";
+ const connectionString = await readSecret(
+ process.env["DATABASE_SECRET_PATH"],
+ );
try {
- const res = await connect(connStr);
+ const res = await connect(connectionString);
if (res.connection.readyState === 1) {
console.log("[MONGODB] Connected successfully!");
} else {
- console.error("[MONGODB] Failed to connect to ", connStr);
+ console.error("[MONGODB] Failed to connect to ", connectionString);
}
} catch (e) {
console.error("[MONGODB] Error connecting to database!");
diff --git a/src/db/schemas/userSchema.js b/src/db/schemas/user.js
index eaddb08..eaddb08 100644
--- a/src/db/schemas/userSchema.js
+++ b/src/db/schemas/user.js
diff --git a/src/util/index.js b/src/util/index.js
index e69de29..9a6c774 100644
--- a/src/util/index.js
+++ b/src/util/index.js
@@ -0,0 +1 @@
+export * from "./secretUtils.js";
diff --git a/src/util/secretUtils.js b/src/util/secretUtils.js
new file mode 100644
index 0000000..33e5fef
--- /dev/null
+++ b/src/util/secretUtils.js
@@ -0,0 +1,9 @@
+import fs from "node:fs/promises";
+
+export async function readSecret(path) {
+ if (!path) {
+ throw new Error("Path to secret file is required");
+ }
+ const content = await fs.readFile(path, "utf8");
+ return content.trim();
+}
|