Skip to content

Commit

Permalink
added mongodb connection
Browse files Browse the repository at this point in the history
  • Loading branch information
vliu36 committed Nov 9, 2024
1 parent deb7671 commit 5042a8b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
37 changes: 37 additions & 0 deletions src/routes/connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Connects to MongoDB
// Only need one client instance

const { MongoClient, ServerApiVersion } = require("mongodb");
const USER = process.env.DBUSER;
const PSWD = process.env.DBPASS;
const HOST = process.env.DBHOST;

// Atlas connection string
const uri = `mongodb+srv://${USER}:${PSWD}@${HOST}/?retryWrites=true&w=majority&appName=LuminosityCluster-0`;

// Create a MongoClient
const client = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
}
);

async function run() {
try {
// Connect to the server
await client.connect();

// Confirm connection
await client.db("admin").command({ ping: 1 });
console.log("Connected to MongoDB. Great success!");
}
finally {
await client.close();
}
}
run().catch(console.dir);

export default client;
2 changes: 1 addition & 1 deletion src/routes/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ app.use("/", router);
app.use(cors());

// Creates CORS Anywhere proxy
// For security purposes, origin and header needs to be specified after proxy URL has been changed to luminosityleds
// TODO: For security purposes, origin and header needs to be specified after proxy URL has been changed to luminosityleds
cors_proxy.createServer({
originWhitelist: [],
requireHeader: [],
Expand Down
17 changes: 0 additions & 17 deletions src/routes/githubTest.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/routes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Routes microservice",
"main": "routes.ts",
"scripts": {
"test": "npx ts-node routes.ts",
"test": "npx ts-node connect.ts",
"account": "npx ts-node github.ts"
},
"keywords": [],
Expand Down
7 changes: 5 additions & 2 deletions src/routes/serverProps.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import GetServerSideProps from 'next'

export const getServerSideProps = (async () => {
const response = await fetch("")
const pageData = await response.json()

return pageData
return {
props: {
todos: pageData
}
}
})

0 comments on commit 5042a8b

Please sign in to comment.