-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Building a backend #20 #40
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asiyani thanks for the PR, that's a ton of work!
I have a couple of thoughts/concerns though.
- The fact that you have to install MongoDB locally, I think a better approach for this would be to suggest the user to create a DB in a service like MLab and update the right info under any
.env
file. - Correct me if I'm wrong, but we should avoid hitting the DB for testing unless there's a really strong reason to do so. Maybe we can use sinon for mocking.
An ideal scenario will be to have a Docker container that has everything installed (MongoDB) but I think that's quite some work for one PR.
test/db.test.js
Outdated
accessToken: 'sadjkskajfeifhwgsjfksdfkmcoiwerkhdskfjksladjf', | ||
}); | ||
|
||
let repo = new Repository({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're modifying repo
anywhere else, you can change this to a const
test/db.test.js
Outdated
describe('Simple DB test', () => { | ||
describe('User', () => { | ||
it('Should save user to db', (done) => { | ||
user.save().then((usr) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we hitting the DB here? If yes we should change things, maybe consider using sinon
for mocking.
test/db.test.js
Outdated
language: 'Javascript', | ||
}); | ||
|
||
describe('Simple DB test', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we should try not to nest describe
blocks, this can lead to unexpected behaviour if we ever need to use this
test/db.test.js
Outdated
const { Username } = require('./../server/db/username'); | ||
const { User } = require('./../server/db/user'); | ||
|
||
// console.log(mongoose.connection.host); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code should go away. No commented code here unless there's a super strong reason 👍
server/db/username.js
Outdated
}); | ||
|
||
|
||
let Username = mongoose.model('Username', usernameSchema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use const
in here.
server/db/repositories.js
Outdated
}); | ||
|
||
|
||
let Repository = mongoose.model('Repository', repositorySchema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
instead of let
config/config.js
Outdated
process.env.NODE_ENV = 'dev'; | ||
} | ||
|
||
let dotenv = require('dotenv').config({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
instead of let
@@ -1 +1,2 @@ | |||
node_modules | |||
.vscode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
README.md
Outdated
## Getting Started | ||
##### Pre-Installation Requirements | ||
###### Node | ||
- Download and install latest stable version of [Node](https://nodejs.org/en/download/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should specify what version are we using and add that to the package.json under "engines"
too.
README.md
Outdated
- Download and install latest stable version of [Node](https://nodejs.org/en/download/). | ||
|
||
###### MongoDb | ||
- Download and Install [MongoDB Community Edition](https://docs.mongodb.com/manual/installation/#mongodb-community-edition). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for Mongo, what version should we (everybody contributing) should use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change Arrow functions to regular functions in tests.
test/db.test.js
Outdated
language: 'Javascript', | ||
}); | ||
|
||
describe('Simple DB test', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also Mocha doesn't like arrow functions at all, we should move to function() { ... }
. More info here https://mochajs.org/#arrow-functions
@asiyani Cool work man 👍 @alejandronanez Should I wait for this PR to merge, so that I can work on |
Yes sir! |
package.json
Outdated
"dependencies": {} | ||
"dependencies": { | ||
"dotenv": "^4.0.0", | ||
"expect": "^1.20.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a devDependency
instead of a dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should discuss what's the best way to do tests + DB setup later.
Good work @asiyani just change that devpendency into devDependency
@asiyani fix conflicts on index.html and we should be good to go 👍 |
I didnt change anything in index.html just moved it to public folder...
…On Fri, 2 Jun 2017, 1:36 pm Alejandro Ñáñez Ortiz, ***@***.***> wrote:
@asiyani <https://github.com/asiyani> fix conflicts on index.html and we
should be good to go 👍
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGz7sOoxkh_CsvCDjmvFtTvIyoCfoRnJks5sAAHLgaJpZM4NtnkN>
.
|
Oh well, maybe that's the issue. Anyway we can't merge until that's resolved though :( Let me know if you have any issues with those conflicts maybe I can jump in. |
I need index.html in public folder, otherwise i need to create route for index.html |
What merge conflict are you seeing? Feel free to change whatever you think
is necessary to solve the conflict so we can merge your pr.
…On Fri, Jun 2, 2017 at 7:52 AM Ashok ***@***.***> wrote:
I need index.html in public folder, otherwise i need to create route for
index.html
Ideally that file should be in public folder.
Do you want me too move it to root for now just to merge PR.and then we
move it back to public folder?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAcYUk0ekBF1VnDGk1ugDbico3AUbgAdks5sAAV5gaJpZM4NtnkN>
.
|
@asiyani You moved the index.html to public folder. After I made a change in the original index.html. Therefore, the Thoughts @alejandronanez |
Yeah that makes sense!
…On Fri, Jun 2, 2017 at 9:04 AM Mubaris NK ***@***.***> wrote:
@asiyani <https://github.com/asiyani> You moved the index.html to public
folder. After I made a change in the original index.html. Therefore, the git
mv didn't work properly. If you move the new index.html to public folder,
it might work.
Thoughts @alejandronanez <https://github.com/alejandronanez>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAcYUpRTSHbqwry-C4Pr8Tes_RxxFr8Iks5sABZfgaJpZM4NtnkN>
.
|
conflicts are now resolved. |
Good stuff boys |
This PR adds Nodejs and MongoDB as the backend to this project. Current functionality for this app is not disturbed. After running
yarn start
website works as it is working now.js
,css
andindex.html
file to thepublic
folder.server
,config
andtest
.app.js
,db
androutes
folder.db
folder contains schema/model for MongoDB database.routes
folder contains js files related to APIs and other web routesconfig
folder got the configuration fordotenv
to load Nodejs environment variables.MongoDB model
Routes
GET /api/username/all
-> will send username list as jasonGET /user
,GET /user/login
,GET /user/logout
-> will just print message on web.Configuration
dotenv
settings..dev.env
and.test.env
MONGODB_URI
is different in both files because we don't want to run lots of test on main db.Test
Mocha
andexpect
for backend testing.yarn run test-node
Readme
Please review this folder structure and code. let me know what you guys think?
is DB schema properties enough or we need some additional information? I think we should create another issue to discuss schema design.