generated from UoaWDCC/react-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from UoaWDCC/DB_Connection
Set up database connection
- Loading branch information
Showing
7 changed files
with
1,766 additions
and
1,291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Environment Variables for Database Connection | ||
|
||
# Create a '.env' file under the api directory of the project and add the following variable: | ||
# MONGODB_URI=mongodb+srv://fsae:cD5pAQGsceFvdle7@cluster0.rropzcv.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0 | ||
|
||
# Original config without using environment variables were: | ||
# name: mongoDB | ||
# connector: MongoDB | ||
# url: mongodb+srv://fsae:cD5pAQGsceFvdle7@cluster0.rropzcv.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0 | ||
# host: cluster0.rropzcv.mongodb.net | ||
# port: 27017 | ||
# user: fsae | ||
# password: '' | ||
# database: '' | ||
# useNewUrlParser: true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './dev-in-mem.datasource'; | ||
export * from './mongo-db.datasource'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; | ||
import {juggler} from '@loopback/repository'; | ||
|
||
const config = { | ||
name: 'mongoDB', | ||
connector: 'mongodb', | ||
url: process.env.MONGODB_URI, // Using environment variable | ||
useNewUrlParser: true | ||
}; | ||
|
||
// Observe application's life cycle to disconnect the datasource when | ||
// application is stopped. This allows the application to be shut down | ||
// gracefully. The `stop()` method is inherited from `juggler.DataSource`. | ||
// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html | ||
|
||
@lifeCycleObserver('datasource') | ||
export class MongoDbDataSource extends juggler.DataSource | ||
implements LifeCycleObserver { | ||
static dataSourceName = 'mongoDB'; | ||
static readonly defaultConfig = config; | ||
|
||
constructor( | ||
@inject('datasources.config.mongoDB', {optional: true}) | ||
dsConfig: object = config, | ||
) { | ||
super(dsConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.