Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
PORT=5005
TOKEN_SECRET=1r0Nh4cK
EXTERNAL_URL=
CLIENT_URL=
TOKEN_SECRET=
MONGODB_URI=
PORT=
DATABASE_URL=
17 changes: 15 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ require("./config")(app);


// 👇 Start handling routes here

const dashboardRouter = require("./routes/dashboard.routes")
app.use("/", dashboardRouter)

const allRoutes = require("./routes");
app.use("/api", allRoutes);

Expand All @@ -19,8 +23,17 @@ app.use("/api", isAuthenticated, projectRouter);
const taskRouter = require("./routes/task.routes");
app.use("/api", isAuthenticated, taskRouter);

const authRouter = require("./routes/auth.routes");
app.use("/auth", authRouter);
const userAuthRouter = require("./routes/userAuth.routes");
app.use("/auth", userAuthRouter);

const therapistAuthRouter = require("./routes/therapistAuth.routes");
app.use("/therapist", therapistAuthRouter);

const therapistRouter = require("./routes/therapist.routes");
app.use("/therapist", isAuthenticated, therapistRouter)

const GPTRouter = require("./routes/gpt.routes");
app.use("/ai-therapist", GPTRouter);

require("./error-handling")(app);

Expand Down
7 changes: 6 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ const cookieParser = require("cookie-parser");

const cors = require("cors");


const client = process.env.CLIENT_URL || "http://localhost:5173"

// Middleware configuration
module.exports = (app) => {
// Because this is a server that will accept requests from outside and it will be hosted ona server with a `proxy`, express needs to know that it should trust that setting.
// Services like heroku use something called a proxy and you need to add this to your server
app.set("trust proxy", 1);

// UPDATED FOR LIVE DEPLOYMENT

app.use(
cors({
origin: ["http://localhost:3000"],
origin: [client],
})
);

Expand Down
2 changes: 1 addition & 1 deletion db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const mongoose = require("mongoose");
// ℹ️ Sets the MongoDB URI for our app to have access to it.
// If no env has been set, we dynamically set it to whatever the folder name was upon the creation of the app

const MONGO_URI = process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/project-management-server";
const MONGO_URI = process.env.DATABASE_URL ||process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/bookworm-local-test-db";

mongoose
.connect(MONGO_URI)
Expand Down
2 changes: 1 addition & 1 deletion error-handling/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = (app) => {
app.use((req, res, next) => {
// this middleware runs whenever requested page is not available
res.status(404).json({ errorMessage: "This route does not exist" });
res.status(404).json({ errorMessage: "This route does not exist, will never exist, or is yet to be created!" });
});

app.use((err, req, res, next) => {
Expand Down
17 changes: 17 additions & 0 deletions models/Therapist.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require("mongoose");
const { Schema, model } = mongoose;

const therapistSchema = new Schema({
email: { type: String, unique: true, required: true },
password: { type: String, required: true },
name: { type: String, required: true },
location: { type: String, required: true },
price: { type: Number, required: true },
languages: [{ type: String, required: true }],
approach: [{ type: String, required: true }],
specialization: [{ type: String, required: true }],
availability: [{ type: String, required: true }],
appointments: [{ type: Schema.Types.ObjectId, ref: "Appointment" }]
});

module.exports = model("Therapist", therapistSchema);
76 changes: 35 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions routes/dashboard.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const router = require("express").Router();

router.get("/", (req, res, next) => {
res.json("Welcome to the Dashboard, all route calls are based off api-address/api/*. In the future we will implement a UI interface for our backend - an admin dashboard. - Stephen, Andy, Devin");
});

module.exports = router;
41 changes: 41 additions & 0 deletions routes/gpt.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const express = require("express");
const router = express.Router();
const mongoose = require("mongoose");
const dotenv = require("dotenv");
dotenv.config();

const chatAPIKey = process.env.OPENAI_API_KEY;

router.post("/completions", async (req, res, next) => {
const options = {
method: "POST",
headers: {
Authorization: `Bearer ${chatAPIKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content:
"You are an empathetic companion on an emotional wellbeing app. You offer mental health tips and advice to users based on their prompts. Do not assume the role of a professional and remind them of that.",
},
{ role: "user", content: req.body.message }],
max_tokens: 500,
}),
};
try {
const response = await fetch(
"https://api.openai.com/v1/chat/completions",
options
);
const data = await response.json();
res.send(data);
} catch (error) {
console.log(error);
}
});


module.exports = router;
2 changes: 1 addition & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const router = require("express").Router();

router.get("/", (req, res, next) => {
res.json("All good in here");
res.json("You are on the API Route");
});

module.exports = router;
Loading