Skip to content

Commit

Permalink
Merge pull request #40 from asiyani/master
Browse files Browse the repository at this point in the history
Create a Backend
  • Loading branch information
mubaris committed Jun 3, 2017
2 parents cd46df4 + 17fab19 commit 16ca70a
Show file tree
Hide file tree
Showing 25 changed files with 815 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.vscode
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
[![Join the chat at https://gitter.im/curiositylab/curiosity](https://badges.gitter.im/curiositylab/curiosity.svg)](https://gitter.im/curiositylab/curiosity?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a28af21730b647da8a84974696776cc0)](https://www.codacy.com/app/mubaris/curiosity?utm_source=github.com&utm_medium=referral&utm_content=mubaris/curiosity&utm_campaign=badger)
[![Build Status](https://travis-ci.org/mubaris/curiosity.svg?branch=master)](https://travis-ci.org/mubaris/curiosity)
[![CircleCI](https://circleci.com/gh/mubaris/curiosity.svg?style=svg)](https://circleci.com/gh/mubaris/curiosity)
[![Build Status](https://travis-ci.org/curiositylab/curiosity.svg?branch=master)](https://travis-ci.org/curiositylab/curiosity)
[![Say Thanks](https://img.shields.io/badge/Say%20Thanks!-%F0%9F%A6%89-1EAEDB.svg)](https://saythanks.io/to/mubaris)

Find amazing github projects as a feed. :zap: :zap:
Expand All @@ -31,6 +30,62 @@ I've collected usernames of amazing stargazers :star: in Github. By using Github

You need to submit Github Token to access Github API.

## Getting Started
##### Pre-Installation Requirements
###### Node
- Download and install latest stable version of [Node](https://nodejs.org/en/download/). This app is tested on Node version v6.10.3

###### MongoDb
- Download and Install [MongoDB Community Edition] (https://docs.mongodb.com/manual/installation/#mongodb-community-edition). This app is tested on MongoDB version v3.4.1

- Create new data directory for mondoDB.
```bash
mkdir -p </path/to/mongodb-data>
```
- Run MongoDB
```bash
mongod --dbpath </path/to/mongodb-data>
```


Now you should have mongoDB server running. If any issue please visit [mongoDB Doc](https://docs.mongodb.com/manual/installation/#tutorials).

Open another terminal/Command Prompt to clone this App.

##### Installing and running curiosity

```bash
# Rest of the guide assumes you already have MongoDB installed and MongoDB server is running.

# Get the latest version
git clone https://github.com/curiositylab/curiosity

# Change directory
cd curiosity

# First time install only
yarn install

# Start the app
yarn run start
```
If installation is successful You should see following message. visit 'http://localhost:3000' to view website.
```
NODE_ENV -> dev
MONGODB_URI -> mongodb://127.0.0.1:27017/curiosity
Starting server on port 3000.
```

Other Scripts for developement and testing.
```bash
# run test for the app
yarn run test-node

# Start app with watch (10s delay)
yarn run watch
```


## Tools I used

* [SweetAlert2](https://limonte.github.io/sweetalert2/)
Expand Down
12 changes: 12 additions & 0 deletions config/.dev.env
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:-
13 changes: 13 additions & 0 deletions config/.test.env
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:-
10 changes: 10 additions & 0 deletions config/config.js
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);
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,28 @@
"repository": "git@github.com:mubaris/curiosity.git",
"author": "Mubaris",
"license": "MIT",
"engines": {
"node": ">=6.0.0"
},
"devDependencies": {
"codecov": "^2.2.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.3.0",
"mocha": "^3.4.2"
"mocha": "^3.4.2",
"dotenv": "^4.0.0",
"expect": "^1.20.2"
},
"scripts": {
"lint": "eslint js/**/*.js"
"lint": "eslint js/**/*.js",
"test-node": "NODE_ENV=test mocha test/**.test.js",
"watch": "nodemon --delay 10 server/app.js",
"start": "node server/app.js"
},
"dependencies": {}
"dependencies": {
"express": "^4.15.3",
"express-session": "^1.15.3",
"mongodb": "^2.2.27",
"mongoose": "^4.10.4"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions index.html → public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/sweetalert2/6.4.4/sweetalert2.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/emojify.js/1.1.0/css/basic/emojify.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="css/emoji.css">
<link rel="stylesheet" href="emoji/emoji.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Code+Pro">
<title>Curiosity</title>
Expand Down Expand Up @@ -53,7 +53,7 @@ <h1>Curiosity</h1>
<script type="text/javascript" src="https://cdn.jsdelivr.net/sweetalert2/6.4.4/sweetalert2.js"></script>
<script type="text/javascript" src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript" src="js/infinite-scroll.js"></script>
<script type="text/javascript" src="js/emoji.js"></script>
<script type="text/javascript" src="emoji/emoji.js"></script>
<script type="text/javascript" src="js/usernames.js"></script>
<script type="text/javascript" src="js/languages.js"></script>
<script type="text/javascript" src="js/languageSelection.js"></script>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions server/app.js
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;

9 changes: 9 additions & 0 deletions server/db/mongoose.js
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;
21 changes: 21 additions & 0 deletions server/db/repositories.js
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;
19 changes: 19 additions & 0 deletions server/db/user.js
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;
24 changes: 24 additions & 0 deletions server/db/username.js
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;
51 changes: 51 additions & 0 deletions server/routes/api/username.js
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;
20 changes: 20 additions & 0 deletions server/routes/user.js
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;
49 changes: 49 additions & 0 deletions test/db.test.js
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));
});
});


Loading

0 comments on commit 16ca70a

Please sign in to comment.