-
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.
- Loading branch information
Showing
20 changed files
with
324 additions
and
0 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,20 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"targets": { | ||
"node": "6.10" | ||
} | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
[ | ||
"transform-object-rest-spread", | ||
{ | ||
"useBuiltIns": true | ||
} | ||
] | ||
] | ||
} |
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 @@ | ||
"**/*" |
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 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": "airbnb-base", | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module" | ||
} | ||
} |
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,6 @@ | ||
node_modules | ||
npm-debug.* | ||
yarn.* | ||
yarn-error.* | ||
coverage | ||
.nyc_output |
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,7 @@ | ||
{ | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"printWidth": 85, | ||
"semi": true, | ||
"singleQuote": true | ||
} |
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 @@ | ||
language: node_js | ||
node_js: | ||
- 'stable' | ||
cache: | ||
directories: | ||
- 'node_modules' | ||
script: npm test | ||
after_success: | ||
- npm run coveralls |
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 @@ | ||
web: cross-env NODE_ENV=production nodemon --exec babel-node ./src/server.js |
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,39 @@ | ||
[](https://travis-ci.org/Musigwa/SendIT-API) | ||
[](https://coveralls.io/github/Musigwa/SendIT-API?branch=parcels-management) | ||
[](https://codeclimate.com/github/Musigwa/SendIT-API/maintainability) | ||
|
||
# SendIT-API | ||
|
||
This is the nodejs express server boilerplate to help you setup your project structure to chick off the ground as fast as possible. | ||
|
||
## How to get started | ||
|
||
1. Simply clone/download or folk this repository and just open it with your favolite editor. | ||
2. make sure you have the node enviroment installed on your computer, or follow https://nodejs.org/en/download/ to install it. it is recommended to install the LTS version. or you can install the latest if you want to play around with its new features. | ||
3. check whether you have a complete node environment install using the following commands: | ||
1. node -v to check your node environment version | ||
2. npm -v to check your node package manager version | ||
The node installation comes with npm(node package manager) by default, but you can choose either yarn https://yarnpkg.com/lang/en/docs/install/ if you prefer. | ||
4. After all, open your project folder location in a terminal and type one of the following commands: | ||
|
||
### yarn install (if you are using yarn as your package manager) or | ||
|
||
### npm install (if you are using npm as your package manager) | ||
|
||
### can i start the server locally and play around with it on my own (?) | ||
|
||
Obviously, yes. after getting the environment set up, you can open the project location in your terminal and te type yarn server or npm server,. you'll see the logs telling you the port on which your server is using or throws an error if any. | ||
|
||
## Can i contribute or build my own from this server(?) | ||
|
||
Yes you can use this node server to build your own. Once cloned/downloaded or folked, feel free to open any of the files contained in either folders and start editing the codes to see the changes. | ||
|
||
Or if you want to contribute to this repo, please pull the request to join me. | ||
|
||
## Having trouble using this project(?) | ||
|
||
1. Email: [email protected] | ||
2. Mobile || Whatsapp: +250785782928 | ||
3. Twitter: #PacificMusigwa | ||
|
||
### Every question is welcome |
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,5 @@ | ||
{ | ||
"env": { | ||
"JWT_KEY": "your_key" | ||
} | ||
} |
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,48 @@ | ||
{ | ||
"name": "appname", | ||
"version": "1.0.0", | ||
"description": "add the project description here", | ||
"main": "./src/server.js", | ||
"author": "MUREKATETE Diane", | ||
"license": "MIT", | ||
"scripts": { | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
"test": "nyc --reporter=text --reporter=lcov mocha --timeout 25000 --require babel-register {tests,tests/**}/*.spec.js --exit || true", | ||
"server": "cross-env NODE_ENV=dev nodemon --exec babel-node ./src/server/index.js" | ||
}, | ||
"engines": { | ||
"node": "8.12.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "provide your the project repo url" | ||
}, | ||
"dependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"bcrypt": "^3.0.2", | ||
"bcrypt-nodejs": "0.0.3", | ||
"cross-env": "5.2.0", | ||
"express": "4.16.4", | ||
"joi": "^14.0.4", | ||
"jsonwebtoken": "8.3.0", | ||
"morgan": "1.9.1", | ||
"multer": "1.4.1", | ||
"nodemon": "^1.18.6" | ||
}, | ||
"devDependencies": { | ||
"request": "^2.88.0", | ||
"babel-eslint": "^10.0.1", | ||
"chai": "4.2.0", | ||
"chai-http": "^4.2.0", | ||
"coveralls": "^3.0.2", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"prettier": "^1.14.3", | ||
"prettier-eslint": "^8.8.2", | ||
"prettier-eslint-cli": "^4.7.1", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.14.0" | ||
} | ||
} |
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,4 @@ | ||
export default { | ||
PORT: process.env.PORT || 3000, | ||
baseUrl: '/api/v1', | ||
}; |
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,29 @@ | ||
import Joi from 'joi'; | ||
import { meetups } from '../database'; | ||
|
||
const createMeetups = (req, res) => { | ||
const schema = { | ||
topic: Joi.string() | ||
.min(4) | ||
.required(), | ||
location: Joi.string() | ||
.min(4) | ||
.required(), | ||
happeningOn: Joi.string() | ||
.min(4) | ||
.required(), | ||
tags: Joi.string() | ||
.min(4) | ||
.required(), | ||
}; | ||
const result = Joi.validate(req.body, schema); | ||
|
||
if (result.error) { | ||
res.status(404).send(result.error.details[0].message); | ||
return; | ||
} | ||
const meetup = { id: meetups.length + 1, ...req.body }; | ||
meetups.push(meetup); | ||
return res.send(meetup); | ||
}; | ||
export { createMeetups }; |
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,34 @@ | ||
// write down some database configurations here | ||
const user = { | ||
id: 1, | ||
firstname: 'gloria', | ||
lastname: 'atete', | ||
othername: 'diane', | ||
email: '[email protected]', | ||
phonenumber: '0782798310', | ||
username: 'murediane', | ||
registered: new Date(), | ||
isadmin: true, | ||
}; | ||
const meetups = [ | ||
{ | ||
id: 1, | ||
createdOn: new Date('9-1-2019'), | ||
location: 'kigali', | ||
image: '', | ||
topic: 'introduction to javascript', | ||
happeningOn: new Date('Thu Jan 9 2018 15:30 GMT'), | ||
tags: 'javascript', | ||
}, | ||
]; | ||
|
||
const question = { | ||
id: 1, | ||
createdOn: new Date(), | ||
createdBy: 1, | ||
meetup: 1, | ||
title: '', | ||
body: '', | ||
votes: 1, | ||
}; | ||
export { user, meetups, question }; |
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,23 @@ | ||
import express from 'express'; | ||
import morgan from 'morgan'; | ||
|
||
import constants from './configuration/constants'; | ||
import middlewares from './middleware'; | ||
|
||
const server = express(); | ||
server.use(morgan('dev')); | ||
server.use(express.json()); | ||
|
||
// Passing all of our APIs config/endpoints to our express server to use them | ||
|
||
middlewares(server); | ||
|
||
// Starting our Express server and pass it the port to listen to. | ||
|
||
server.listen(constants.PORT, () => { | ||
console.log(`server is running to port:${constants.PORT}`); | ||
}); | ||
|
||
// Exported the server for testing purpose // | ||
|
||
export default server; |
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 @@ | ||
import routes from '../routes'; | ||
import constants from '../configuration/constants'; | ||
|
||
export default server => { | ||
// Headers configuration | ||
|
||
server.use((req, res, next) => { | ||
res.header('Access-Control-Allow-Origin', '*'); | ||
res.header( | ||
'Access-Control-Allow-Headers', | ||
'Origin,X-Requested-With,Content-Type,Accept,Authorization', | ||
); | ||
res.header('Access-Control-Expose-Header', 'X-Total-Count'); | ||
if (req.method === 'OPTIONS') { | ||
res.header('Access-Control-Allow-Methods', 'PUT,GET,POST,PATCH,DELETE'); | ||
return res.status(200).json({}); | ||
} | ||
next(); | ||
}); | ||
server.use(constants.baseUrl, routes); | ||
server.use((req, res) => | ||
res.status(404).json({ message: `invalid url ${req.url}` }), | ||
); | ||
}; |
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 @@ | ||
import express, { Router } from 'express'; | ||
import meetupRoutes from './meetup'; | ||
const routes = Router(); | ||
|
||
// API ENTRYPOINT | ||
|
||
const entryPoint = Router(); | ||
entryPoint.get('/', (req, res) => { | ||
res.status(200).json({ message: 'welcome' }); | ||
}); | ||
|
||
// UPLOADS ENDPOINT | ||
|
||
const uploads = ('/uploads', express.static('uploads')); | ||
|
||
//ALL ENDPOINTS | ||
|
||
routes.use(entryPoint, meetupRoutes, uploads); | ||
|
||
export default routes; |
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,8 @@ | ||
import Router from 'express'; | ||
import { createMeetups } from '../controllers/meetups'; | ||
const router = Router(); | ||
const entry = '/meetups'; | ||
// create Meetups route | ||
|
||
router.post(`${entry}`, createMeetups); | ||
export default 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 @@ | ||
// write your tests down here |
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,27 @@ | ||
import chai from 'chai'; | ||
import chaiHTTP from 'chai-http'; | ||
|
||
import server from '../src/server'; | ||
import { baseUrl } from './testData'; | ||
|
||
const should = chai.should(); | ||
chai.use(chaiHTTP); | ||
|
||
// Tests the entrypoint of the server | ||
|
||
describe('/GET server', () => { | ||
it("it should return an object with property message:'welcome'", done => { | ||
const exp = { msg: 'welcome' }; | ||
chai | ||
.request(server) | ||
.get(baseUrl) | ||
.end((err, res) => { | ||
res.should.have.status(200); | ||
res.body.should.be.a('object'); | ||
res.body.should.have | ||
.property('message') | ||
.eql(exp.msg, `expected message property to be '${exp.msg}'`); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,5 @@ | ||
// write your test data down here | ||
const baseUrl = "/api/v1"; | ||
|
||
// export the here | ||
export { baseUrl }; |