Skip to content

Commit b864ed7

Browse files
author
tomcat6
committed
Initialize app from template
0 parents  commit b864ed7

File tree

15 files changed

+773
-0
lines changed

15 files changed

+773
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
*~
3+
cov-*
4+
coverage
5+
plato
6+
.idea

.jshintrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"asi" : true,
3+
"camelcase" : false,
4+
"bitwise" : false,
5+
"unused" : true,
6+
"laxbreak" : true,
7+
"laxcomma" : true,
8+
"curly" : false,
9+
"eqeqeq" : true,
10+
"evil" : true,
11+
"forin" : false,
12+
"immed" : true,
13+
"latedef" : true,
14+
"newcap" : true,
15+
"noarg" : true,
16+
"noempty" : true,
17+
"nonew" : true,
18+
"plusplus" : false,
19+
"regexp" : true,
20+
"undef" : true,
21+
"strict" : false,
22+
"sub" : true,
23+
"trailing" : true,
24+
"node" : true,
25+
"maxerr" : 100,
26+
"indent" : 2
27+
}

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
sudo: false
5+
before_install:
6+
- npm install -g [email protected]
7+
- npm install -g grunt-cli
8+
install: npm install

Grunt-ReadMe.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Grunt
2+
3+
This template uses [Grunt](http://gruntjs.com/), the Javascript Task Runner. To use Grunt with this Template App, do the following:
4+
5+
* Install grunt: ```npm install -g grunt-cli```
6+
* In your App directory, run: ```npm install```. This installs Grunt plugins, etc for use with this App.
7+
8+
# Tasks
9+
10+
The following are a short overview of the Grunt tasks available for this App. You can get a full list of tasks from Grunt with ```grunt --help```.
11+
12+
## grunt serve
13+
14+
Run ```grunt serve``` to serve this App locally. By default this App will run on http://localhost:8001.
15+
16+
Note that 'grunt serve' supports live reload, i.e. it will monitor for any changes in your node.js application and automatically restart the server
17+
18+
## grunt debug
19+
20+
Run ```grunt debug``` to debug this App locally. This task uses [Node Inspector](https://github.com/node-inspector/node-inspector) to debug your application, and will open the Debugger at 'application.js' in Google Chrome. See the documentation for [Node Inspector](https://github.com/node-inspector/node-inspector) for more information on how to use Node Inspector.
21+
22+
## grunt test
23+
24+
Run ```grunt test``` to run the unit tests for this App.
25+
26+
## grunt coverage
27+
28+
This App uses [Istanbul](https://github.com/gotwarlost/istanbul) for generating code coverage for your tests.
29+
30+
Run ```grunt coverage``` to run code coverage for this App.
31+
32+
## grunt analysis
33+
34+
Run ```grunt analysis``` to get a static analysis report of your code. This task uses [Plato](https://github.com/es-analysis/plato) to generate the report. See the documentaion for [Plato](https://github.com/es-analysis/plato) for more information on how to use and configure Plato.
35+
36+
## Environment variables
37+
38+
The [grunt env](https://www.npmjs.org/package/grunt-env) plugin is included by default. To set your own environment variables, modify the `env` config accordingly, e.g.
39+
40+
```
41+
env : {
42+
options : {},
43+
// Sample environment variable - see https://github.com/jsoverson/grunt-env for more information
44+
local : {
45+
SAMPLE_ENV_VAR : 'sample-env-var'
46+
}
47+
},
48+
```
49+
50+
Alternatively you can load environment variables from a local file, see the `grunt env` [documentation](https://www.npmjs.org/package/grunt-env#using-external-files) for more details.
51+
52+

Gruntfile.js

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
'use strict';
2+
3+
module.exports = function(grunt) {
4+
require('time-grunt')(grunt);
5+
// Project Configuration
6+
grunt.initConfig({
7+
pkg: grunt.file.readJSON('package.json'),
8+
watch: {
9+
js: {
10+
files: ['gruntfile.js', 'application.js', 'lib/**/*.js', 'test/**/*.js'],
11+
options: {
12+
livereload: true
13+
}
14+
},
15+
html: {
16+
files: ['public/views/**', 'app/views/**'],
17+
options: {
18+
livereload: true
19+
}
20+
}
21+
},
22+
nodemon: {
23+
dev: {
24+
script: 'application.js',
25+
options: {
26+
args: [],
27+
ignore: ['public/**'],
28+
ext: 'js,html',
29+
nodeArgs: [],
30+
delayTime: 1,
31+
env: {
32+
PORT: 3000
33+
},
34+
cwd: __dirname
35+
}
36+
}
37+
},
38+
concurrent: {
39+
serve: ['nodemon', 'watch'],
40+
debug: ['node-inspector', 'shell:debug', 'open:debug'],
41+
options: {
42+
logConcurrentOutput: true
43+
}
44+
},
45+
env: {
46+
options: {},
47+
// environment variables - see https://github.com/jsoverson/grunt-env for more information
48+
local: {
49+
FH_USE_LOCAL_DB: true,
50+
FH_SERVICE_MAP: function() {
51+
/*
52+
* Define the mappings for your services here - for local development.
53+
* You must provide a mapping for each service you wish to access
54+
* This can be a mapping to a locally running instance of the service (for local development)
55+
* or a remote instance.
56+
*/
57+
var serviceMap = {
58+
'SERVICE_GUID_1': 'http://127.0.0.1:8010',
59+
'SERVICE_GUID_2': 'https://host-and-path-to-service'
60+
};
61+
return JSON.stringify(serviceMap);
62+
}
63+
}
64+
},
65+
'node-inspector': {
66+
dev: {}
67+
},
68+
shell: {
69+
debug: {
70+
options: {
71+
stdout: true
72+
},
73+
command: 'env NODE_PATH=. node --debug-brk application.js'
74+
},
75+
unit: {
76+
options: {
77+
stdout: true,
78+
stderr: true
79+
},
80+
command: 'env NODE_PATH=. ./node_modules/.bin/mocha -A -u exports --recursive test/unit/'
81+
},
82+
accept: {
83+
options: {
84+
stdout: true,
85+
stderr: true
86+
},
87+
command: 'env NODE_PATH=. ./node_modules/.bin/mocha -A -u exports --recursive test/server.js test/accept/'
88+
},
89+
coverage_unit: {
90+
options: {
91+
stdout: true,
92+
stderr: true
93+
},
94+
command: [
95+
'rm -rf coverage cov-unit',
96+
'env NODE_PATH=. ./node_modules/.bin/istanbul cover --dir cov-unit ./node_modules/.bin/turbo -- test/unit',
97+
'./node_modules/.bin/istanbul report',
98+
'echo "See html coverage at: `pwd`/coverage/lcov-report/index.html"'
99+
].join('&&')
100+
},
101+
coverage_accept: {
102+
options: {
103+
stdout: true,
104+
stderr: true
105+
},
106+
command: [
107+
'rm -rf coverage cov-accept',
108+
'env NODE_PATH=. ./node_modules/.bin/istanbul cover --dir cov-accept ./node_modules/.bin/turbo -- --setUp=test/accept/server.js --tearDown=test/accept/server.js test/accept',
109+
'./node_modules/.bin/istanbul report',
110+
'echo "See html coverage at: `pwd`/coverage/lcov-report/index.html"'
111+
].join('&&')
112+
}
113+
},
114+
open: {
115+
debug: {
116+
path: 'http://127.0.0.1:8080/debug?port=5858',
117+
app: 'Google Chrome'
118+
},
119+
platoReport: {
120+
path: './plato/index.html',
121+
app: 'Google Chrome'
122+
}
123+
},
124+
plato: {
125+
src: {
126+
options: {
127+
jshint: grunt.file.readJSON('.jshintrc')
128+
},
129+
files: {
130+
'plato': ['lib/**/*.js']
131+
}
132+
}
133+
},
134+
jshint: {
135+
files: ['*.js', 'lib/**/*.js', 'test/**/*.js'],
136+
options: {
137+
jshintrc: true
138+
}
139+
},
140+
});
141+
142+
// Load NPM tasks
143+
require('load-grunt-tasks')(grunt, {
144+
scope: 'devDependencies'
145+
});
146+
grunt.loadNpmTasks('grunt-contrib-jshint');
147+
148+
// Testing tasks
149+
grunt.registerTask('test', ['jshint', 'shell:unit', 'shell:accept']);
150+
grunt.registerTask('unit', ['jshint', 'shell:unit']);
151+
grunt.registerTask('accept', ['env:local', 'shell:accept']);
152+
153+
// Coverate tasks
154+
grunt.registerTask('coverage', ['shell:coverage_unit', 'shell:coverage_accept']);
155+
grunt.registerTask('coverage-unit', ['shell:coverage_unit']);
156+
grunt.registerTask('coverage-accept', ['env:local', 'shell:coverage_accept']);
157+
158+
159+
grunt.registerTask('analysis', ['plato:src', 'open:platoReport']);
160+
161+
grunt.registerTask('serve', ['env:local', 'concurrent:serve']);
162+
grunt.registerTask('debug', ['env:local', 'concurrent:debug']);
163+
grunt.registerTask('default', ['serve']);
164+
};

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2014 FeedHenry Ltd, All Rights Reserved
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
20+
21+
This software may download additional open source software components upon install
22+
that are distributed under separate terms and conditions. Please see the license
23+
information provided in the individual software components for more information.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# FeedHenry Hello World MBaaS Server
2+
3+
This is a blank 'hello world' FeedHenry MBaaS. Use it as a starting point for building your APIs.
4+
5+
# Group Hello World API
6+
7+
# hello [/hello]
8+
9+
'Hello world' endpoint.
10+
11+
## hello [POST]
12+
13+
'Hello world' endpoint.
14+
15+
+ Request (application/json)
16+
+ Body
17+
{
18+
"hello": "world"
19+
}
20+
21+
+ Response 200 (application/json)
22+
+ Body
23+
{
24+
"msg": "Hello world"
25+
}

application.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var mbaasApi = require('fh-mbaas-api');
2+
var express = require('express');
3+
var mbaasExpress = mbaasApi.mbaasExpress();
4+
var cors = require('cors');
5+
6+
// list the endpoints which you want to make securable here
7+
var securableEndpoints;
8+
securableEndpoints = ['/hello'];
9+
10+
var app = express();
11+
12+
// Enable CORS for all requests
13+
app.use(cors());
14+
15+
// Note: the order which we add middleware to Express here is important!
16+
app.use('/sys', mbaasExpress.sys(securableEndpoints));
17+
app.use('/mbaas', mbaasExpress.mbaas);
18+
19+
// allow serving of static files from the public directory
20+
app.use(express.static(__dirname + '/public'));
21+
22+
// Note: important that this is added just before your own Routes
23+
app.use(mbaasExpress.fhmiddleware());
24+
25+
app.use('/hello', require('./lib/hello.js')());
26+
27+
// Important that this is last!
28+
app.use(mbaasExpress.errorHandler());
29+
30+
var port = process.env.FH_PORT || process.env.OPENSHIFT_NODEJS_PORT || 8001;
31+
var host = process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0';
32+
app.listen(port, host, function() {
33+
console.log("App started at: " + new Date() + " on port: " + port);
34+
});

lib/hello.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var express = require('express');
2+
var bodyParser = require('body-parser');
3+
var cors = require('cors');
4+
5+
function helloRoute() {
6+
var hello = new express.Router();
7+
hello.use(cors());
8+
hello.use(bodyParser());
9+
10+
11+
// GET REST endpoint - query params may or may not be populated
12+
hello.get('/', function(req, res) {
13+
console.log(new Date(), 'In hello route GET / req.query=', req.query);
14+
var world = req.query && req.query.hello ? req.query.hello : 'World';
15+
16+
// see http://expressjs.com/4x/api.html#res.json
17+
res.json({msg: 'Hello ' + world});
18+
});
19+
20+
// POST REST endpoint - note we use 'body-parser' middleware above to parse the request body in this route.
21+
// This can also be added in application.js
22+
// See: https://github.com/senchalabs/connect#middleware for a list of Express 4 middleware
23+
hello.post('/', function(req, res) {
24+
console.log(new Date(), 'In hello route POST / req.body=', req.body);
25+
var world = req.body && req.body.hello ? req.body.hello : 'World';
26+
27+
// see http://expressjs.com/4x/api.html#res.json
28+
res.json({msg: 'Hello ' + world});
29+
});
30+
31+
return hello;
32+
}
33+
34+
module.exports = helloRoute;

0 commit comments

Comments
 (0)