-
Notifications
You must be signed in to change notification settings - Fork 65
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 asiyani/master
Create a Backend
- Loading branch information
Showing
25 changed files
with
815 additions
and
16 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
.vscode |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Node ENV for DEVELOPMENT | ||
# Update PRIVATE section below with correct value | ||
# | ||
# | ||
# | ||
|
||
|
||
# Public section:- | ||
MONGODB_URI='mongodb://127.0.0.1:27017/curiosity' | ||
|
||
|
||
# PRIVATE section:- |
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,13 @@ | ||
# Node ENV for TESTING | ||
# Update PRIVATE section below with correct value | ||
# | ||
# | ||
# | ||
|
||
|
||
# Public section:- | ||
MONGODB_URI='mongodb://127.0.0.1:27017/curiosityTEST' | ||
|
||
|
||
|
||
# PRIVATE section:- |
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,10 @@ | ||
if (!process.env.NODE_ENV) { | ||
process.env.NODE_ENV = 'dev'; | ||
} | ||
|
||
const dotenv = require('dotenv').config({ | ||
path: `${__dirname}/.${process.env.NODE_ENV}.env`, | ||
}); | ||
|
||
console.log('NODE_ENV ->', process.env.NODE_ENV); | ||
console.log('MONGODB_URI ->', process.env.MONGODB_URI); |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,21 @@ | ||
require('./../config/config'); | ||
|
||
const express = require('express'); | ||
const { mongoose } = require('./db/mongoose'); | ||
const { usernameRoutes } = require('./routes/api/username'); | ||
const { userRoutes } = require('./routes/user'); | ||
|
||
const app = express(); | ||
const port = process.env.PORT || 3000; | ||
|
||
app.use(express.static(`${__dirname}/../public`)); | ||
|
||
app.use('/user',userRoutes); | ||
app.use('/api/username', usernameRoutes); | ||
|
||
app.listen(port, () => { | ||
console.log(`Starting server on port ${port}.`); | ||
}); | ||
|
||
module.exports.app = app; | ||
|
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,9 @@ | ||
let mongoose = require('mongoose'); | ||
|
||
mongoose.Promise = global.Promise; | ||
|
||
mongoose.connect(process.env.MONGODB_URI, (err) => { | ||
if (err) throw err; | ||
}); | ||
|
||
module.exports = mongoose; |
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,21 @@ | ||
// Repositories | ||
const mongoose = require('./mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const repositorySchema = new Schema({ | ||
_id: mongoose.Schema.Types.ObjectId, | ||
name: String, | ||
html_url: String, | ||
description: String, | ||
stargazers_count: Number, | ||
forks_count: Number, | ||
created_at: Date, | ||
updated_at: Date, | ||
language: String, | ||
}); | ||
|
||
|
||
const Repository = mongoose.model('Repository', repositorySchema); | ||
|
||
module.exports.Repository = Repository; |
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,19 @@ | ||
// Schema for logged in users. | ||
const mongoose = require('./mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const userSchema = new Schema({ | ||
_id: mongoose.Schema.Types.ObjectId, | ||
githubId: Number, | ||
login: String, | ||
name: String, | ||
html_url: String, | ||
accessToken: String, | ||
}); | ||
|
||
|
||
const User = mongoose.model('User', userSchema); | ||
|
||
|
||
module.exports.User = User; |
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,24 @@ | ||
// Schema of usernames of stargazers in Github | ||
const mongoose = require('./mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const usernameSchema = new Schema({ | ||
_id: mongoose.Schema.Types.ObjectId, | ||
githubId: Number, | ||
login: String, | ||
name: String, | ||
html_url: String, | ||
location: String, | ||
bio: String, | ||
public_repos: Number, | ||
public_gists: Number, | ||
followers: Number, | ||
dbLastUpdated: Date, | ||
starredIds: [mongoose.Schema.Types.ObjectId], | ||
}); | ||
|
||
|
||
const Username = mongoose.model('Username', usernameSchema); | ||
|
||
module.exports.Username = Username; |
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,51 @@ | ||
// API related to username here. | ||
|
||
const express = require('express'); | ||
|
||
const router = express.Router(); | ||
|
||
const USERNAMES = [ | ||
'tj', | ||
'addyosmani', | ||
'paulirish', | ||
'passy', | ||
'sindresorhus', | ||
'gaearon', | ||
'defunkt', | ||
'daimajia', | ||
'kvz', | ||
'omgmog', | ||
'yyx990803', | ||
'kennethreitz', | ||
'Trinea', | ||
'JacksonTian', | ||
'substack', | ||
'stormzhang', | ||
'muan', | ||
'onevcat', | ||
'clowwindy', | ||
'getify', | ||
'csu', | ||
'matiasinsaurralde', | ||
'ibireme', | ||
'phodal', | ||
'ryanb', | ||
'isaacs', | ||
'justjavac', | ||
'ChenYilong', | ||
'cusspvz', | ||
'feross', | ||
'm1guelpf', | ||
'brentvatne', | ||
'developit', | ||
'Kureev', | ||
'mxstbr', | ||
'jaredly', | ||
]; | ||
|
||
|
||
router.get('/all', (req, res) => { | ||
res.send(USERNAMES); | ||
}); | ||
|
||
module.exports.usernameRoutes = router; |
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,20 @@ | ||
// logged in/Registered user end point here | ||
const express = require('express'); | ||
|
||
const router = express.Router(); | ||
|
||
// POST '/login' | ||
// delete '/logout' | ||
router.get('/', (req, res) => { | ||
res.send('You reached GET /user end point'); | ||
}); | ||
|
||
router.get('/login', (req, res) => { | ||
res.send('You are logged in !..lol'); | ||
}); | ||
|
||
router.get('/logout', (req, res) => { | ||
res.send('You are logged out !..lol'); | ||
}); | ||
|
||
module.exports.userRoutes = router; |
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,49 @@ | ||
require('./../config/config'); | ||
|
||
const mongoose = require('./../server/db/mongoose'); | ||
const expect = require('expect'); | ||
|
||
const { Repository } = require('./../server/db/repositories'); | ||
const { Username } = require('./../server/db/username'); | ||
const { User } = require('./../server/db/user'); | ||
|
||
|
||
const user = new User({ | ||
_id: new mongoose.Types.ObjectId(), | ||
githubId: 1111111, | ||
login: 'testUser1', | ||
name: 'testUser1', | ||
html_url: 'https://github.com/testUser1', | ||
accessToken: 'sadjkskajfeifhwgsjfksdfkmcoiwerkhdskfjksladjf', | ||
}); | ||
|
||
const repo = new Repository({ | ||
_id: new mongoose.Types.ObjectId(), | ||
name: 'curiosity', | ||
html_url: 'https://github.com/mubaris/curiosity', | ||
description: 'Find Amazing Github Projects', | ||
stargazers_count: 72, | ||
forks_count: 12, | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
language: 'Javascript', | ||
}); | ||
|
||
describe('Simple DB test', function (){ | ||
it('User:Should save user to db', function (done) { | ||
user.save().then((usr) => { | ||
expect(usr._id).toBe(user._id); | ||
done(); | ||
}) | ||
.catch(e => done(e)); | ||
}); | ||
it('Repository:Should save repository to db', function (done) { | ||
repo.save().then((rep) => { | ||
expect(rep._id).toBe(rep._id); | ||
done(); | ||
}) | ||
.catch(e => done(e)); | ||
}); | ||
}); | ||
|
||
|
Oops, something went wrong.