This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
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
0 parents
commit ca31c77
Showing
72 changed files
with
12,989 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,4 @@ | ||
# 4 space indentation | ||
[*.js] | ||
indent_style = space | ||
indent_size = 4 |
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,3 @@ | ||
node_modules/* | ||
test/artifacts/* | ||
/config.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,83 @@ | ||
{ | ||
"maxerr" : 50, // {int} Maximum error before stopping | ||
|
||
// Enforcing | ||
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) | ||
"camelcase" : false, // true: Identifiers must be in camelCase | ||
"curly" : true, // true: Require {} for every new block or scope | ||
"eqeqeq" : true, // true: Require triple equals (===) for comparison | ||
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() | ||
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` | ||
"indent" : 2, // {int} Number of spaces to use for indentation | ||
"latedef" : false, // true: Require variables/functions to be defined before being used | ||
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()` | ||
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` | ||
"noempty" : true, // true: Prohibit use of empty blocks | ||
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment) | ||
"plusplus" : false, // true: Prohibit use of `++` & `--` | ||
"quotmark" : false, // Quotation mark consistency: | ||
// false : do nothing (default) | ||
// true : ensure whatever is used is consistent | ||
// "single" : require single quotes | ||
// "double" : require double quotes | ||
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) | ||
"unused" : "vars", // true: Require all defined variables be used | ||
"strict" : false, // true: Requires all functions run in ES5 Strict Mode | ||
"trailing" : false, // true: Prohibit trailing whitespaces | ||
"maxparams" : false, // {int} Max number of formal params allowed per function | ||
"maxdepth" : false, // {int} Max depth of nested blocks (within functions) | ||
"maxstatements" : false, // {int} Max number statements per function | ||
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function | ||
"maxlen" : false, // {int} Max number of characters per line | ||
|
||
// Relaxing | ||
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) | ||
"boss" : false, // true: Tolerate assignments where comparisons would be expected | ||
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints. | ||
"eqnull" : false, // true: Tolerate use of `== null` | ||
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters) | ||
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) | ||
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) | ||
// (ex: `for each`, multiple try/catch, function expression…) | ||
"evil" : false, // true: Tolerate use of `eval` and `new Function()` | ||
"expr" : true, // true: Tolerate `ExpressionStatement` as Programs | ||
"funcscope" : false, // true: Tolerate defining variables inside control statements" | ||
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') | ||
"iterator" : false, // true: Tolerate using the `__iterator__` property | ||
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block | ||
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings | ||
"laxcomma" : false, // true: Tolerate comma-first style coding | ||
"loopfunc" : false, // true: Tolerate functions being defined in loops | ||
"multistr" : false, // true: Tolerate multi-line strings | ||
"proto" : false, // true: Tolerate using the `__proto__` property | ||
"scripturl" : false, // true: Tolerate script-targeted URLs | ||
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment | ||
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` | ||
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation | ||
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` | ||
"validthis" : false, // true: Tolerate using this in a non-constructor function | ||
|
||
// Environments | ||
"browser" : false, // Web Browser (window, document, etc) | ||
"couch" : false, // CouchDB | ||
"devel" : true, // Development/debugging (alert, confirm, etc) | ||
"dojo" : false, // Dojo Toolkit | ||
"jquery" : false, // jQuery | ||
"mootools" : false, // MooTools | ||
"node" : true, // Node.js | ||
"nonstandard" : true, // Widely adopted globals (escape, unescape, etc) | ||
"prototypejs" : false, // Prototype and Scriptaculous | ||
"rhino" : false, // Rhino | ||
"worker" : false, // Web Workers | ||
"wsh" : false, // Windows Scripting Host | ||
"yui" : false, // Yahoo User Interface | ||
|
||
// Legacy | ||
"nomen" : false, // true: Prohibit dangling `_` in variables | ||
"onevar" : false, // true: Allow only one `var` statement per function | ||
"passfail" : false, // true: Stop on first error | ||
"white" : false, // true: Check against strict whitespace and indentation rules | ||
|
||
// Custom Globals | ||
"predef" : [ ] // additional predefined global variables | ||
} |
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,22 @@ | ||
(The MIT License) | ||
|
||
Copyright (c) 2014 Reza Akhavan <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,202 @@ | ||
# Frame | ||
|
||
An API boilerplate for Node.js. Bring your own front-end. | ||
|
||
|
||
## Technology | ||
|
||
__Primary goal:__ include as few dependencies as possible | ||
|
||
Frame is built with the [hapi.js framework](https://github.com/hapijs/hapi) and | ||
[toolset](https://github.com/hapijs). We're using | ||
[MongoDB](https://github.com/mongodb/node-mongodb-native/) as a data store. We | ||
also user [Nodemailer](https://github.com/andris9/Nodemailer) for email | ||
transport. | ||
|
||
Please [refer to the wiki](https://github.com/jedireza/frame/wiki/) for | ||
more details. | ||
|
||
|
||
## Live demos | ||
|
||
| endpoint | username | password | | ||
|:------------------------------------- |:-------- |:-------- | | ||
| https://hapiframe.herokuapp.com/docs/ | coming | soon | | ||
| https://hapiframe.nodejitsu.com/docs/ | coming | soon | | ||
|
||
[Postman](http://www.getpostman.com/) is a great tool for testing and | ||
developing APIs. | ||
|
||
__Note:__ The live demos have been modified so you cannot change the root user, the root user's linked admin role or the root admin group. This was done in order to keep the API ready to show at all times. | ||
|
||
|
||
## Requirements | ||
|
||
You need [Node.js](http://nodejs.org/download/) and | ||
[MongoDB](http://www.mongodb.org/downloads) installed and running. | ||
|
||
We use [`bcrypt`](https://github.com/ncb000gt/node.bcrypt.js) for hashing | ||
secrets. If you have issues during installation related to `bcrypt` then [refer | ||
to this wiki | ||
page](https://github.com/jedireza/frame/wiki/bcrypt-Installation-Trouble). | ||
|
||
|
||
## Installation | ||
|
||
```bash | ||
$ git clone [email protected]:jedireza/frame.git && cd ./frame | ||
$ npm install | ||
``` | ||
|
||
|
||
## Setup | ||
|
||
__WARNING:__ This will clear all data in existing `users`, `admins` and | ||
`admingroups` MongoDB collections. It will also overwrite an existing | ||
`/config.js` file. | ||
|
||
```bash | ||
$ npm run setup | ||
|
||
# > [email protected] setup /Users/jedireza/projects/frame | ||
# > ./setup.js | ||
|
||
# Project name: (Frame) | ||
# MongoDB URL: (mongodb://localhost:27017/frame) | ||
# Root user email: [email protected] | ||
# Root user password: | ||
# System email: ([email protected]) | ||
# SMTP host: (smtp.gmail.com) | ||
# SMTP port: (465) | ||
# SMTP username: ([email protected]) | ||
# SMTP password: | ||
# Setup complete. | ||
``` | ||
|
||
|
||
## Running the app | ||
|
||
```bash | ||
$ npm start | ||
|
||
# > [email protected] start /Users/jedireza/projects/frame | ||
# > ./node_modules/nodemon/bin/nodemon.js -e js,md server | ||
|
||
# 20 Sep 03:47:15 - [nodemon] v1.2.1 | ||
# 20 Sep 03:47:15 - [nodemon] to restart at any time, enter `rs` | ||
# 20 Sep 03:47:15 - [nodemon] watching: *.* | ||
# 20 Sep 03:47:15 - [nodemon] starting `node server index.js` | ||
# Started the plot device. | ||
``` | ||
|
||
This will start the app using [`nodemon`](https://github.com/remy/nodemon). | ||
`nodemon` will watch for changes and restart the app as needed. | ||
|
||
|
||
## Philosophy | ||
|
||
- Create a user system API | ||
- Don't include a front-end | ||
- Write code in a simple and consistent way | ||
- It's just JavaScript | ||
- 100% test coverage | ||
|
||
|
||
## Features | ||
|
||
- Login system with forgot password and reset password | ||
- Abusive login attempt detection | ||
- User roles for accounts and admins | ||
- Facilities for notes and status updates | ||
- Admin groups with shared permissions | ||
- Admin level permissions that override group permissions | ||
|
||
|
||
## Questions and contributing | ||
|
||
Any issues or questions (no matter how basic), open an issue. Please take the | ||
initiative to include basic debugging information like operating system | ||
and relevant version details such as: | ||
|
||
```bash | ||
$ npm version | ||
|
||
# { http_parser: '1.0', | ||
# node: '0.10.29', | ||
# v8: '3.14.5.9', | ||
# ares: '1.9.0-DEV', | ||
# uv: '0.10.27', | ||
# zlib: '1.2.3', | ||
# modules: '11', | ||
# openssl: '1.0.1h', | ||
# npm: '1.4.20', | ||
# frame: '0.0.0' } | ||
``` | ||
|
||
```bash | ||
$ mongo --version | ||
|
||
# MongoDB shell version: 2.2.1 | ||
``` | ||
|
||
```bash | ||
$ mongod --version | ||
|
||
# db version v2.2.1, pdfile version 4.5 | ||
``` | ||
|
||
Contributions welcome. Your code should: | ||
|
||
- include 100% test coverage | ||
- follow the [hapi.js coding conventions](https://github.com/hapijs/hapi/blob/master/docs/Style.md) | ||
|
||
If you're changing something non-trivial, you may want to submit an issue | ||
first. | ||
|
||
|
||
## Running tests | ||
|
||
[Lab](https://github.com/hapijs/lab) is part of the hapi.js toolset and what we | ||
use to write all of our tests. | ||
|
||
For command line output: | ||
|
||
```bash | ||
$ npm test | ||
|
||
# > [email protected] test /Users/jedireza/projects/frame | ||
# > ./node_modules/lab/bin/lab -c | ||
|
||
# .................................................. | ||
# .................................................. | ||
# .................................................. | ||
# .................................................. | ||
# .................................................. | ||
# ............................. | ||
|
||
# 279 tests complete | ||
# Test duration: 4628 ms | ||
# No global variable leaks detected | ||
# Coverage: 100.00% | ||
``` | ||
|
||
With html code coverage report: | ||
|
||
```bash | ||
$ npm run test-cover | ||
|
||
# > [email protected] test-cover /Users/jedireza/projects/frame | ||
# > ./node_modules/lab/bin/lab -c -r html -o ./test/artifacts/coverage.html && open ./test/artifacts/coverage.html | ||
``` | ||
|
||
This will run the tests and open a web browser to the visual code coverage | ||
artifcacts. The generated source can be found in `/tests/artifacts/coverage.html`. | ||
|
||
|
||
## License | ||
|
||
MIT | ||
|
||
## Don't forget | ||
|
||
What you build with Frame is more important than Frame. |
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,75 @@ | ||
var Confidence = require('confidence'); | ||
var criteria = { | ||
env: process.env.NODE_ENV | ||
}; | ||
|
||
|
||
var config = { | ||
$meta: 'This file configures the plot device.', | ||
projectName: '{{projectName}}', | ||
port: { | ||
api: { | ||
$filter: 'env', | ||
test: 9001, | ||
$default: 8001 | ||
}, | ||
web: { | ||
$filter: 'env', | ||
test: 9000, | ||
$default: 8000 | ||
} | ||
}, | ||
authAttempts: { | ||
forIp: 50, | ||
forIpAndUser: 7 | ||
}, | ||
mongodb: { | ||
$filter: 'env', | ||
production: { | ||
url: process.env.MONGOLAB_URI, | ||
autoIndex: false | ||
}, | ||
test: { | ||
url: '{{mongodbUrl}}-test', | ||
autoIndex: true | ||
}, | ||
$default: { | ||
url: '{{mongodbUrl}}', | ||
autoIndex: true | ||
} | ||
}, | ||
nodemailer: { | ||
host: '{{smtpHost}}', | ||
port: {{smtpPort}}, | ||
secure: true, | ||
auth: { | ||
user: '{{smtpUsername}}', | ||
pass: '{{smtpPassword}}' | ||
} | ||
}, | ||
system: { | ||
fromAddress: { | ||
name: '{{projectName}}', | ||
address: '{{systemEmail}}' | ||
}, | ||
toAddress: { | ||
name: '{{projectName}}', | ||
address: '{{systemEmail}}' | ||
} | ||
} | ||
}; | ||
|
||
|
||
var store = new Confidence.Store(config); | ||
|
||
|
||
exports.get = function (key) { | ||
|
||
return store.get(key, criteria); | ||
}; | ||
|
||
|
||
exports.meta = function (key) { | ||
|
||
return store.meta(key, criteria); | ||
}; |
Oops, something went wrong.