Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/mean/master'
Conflicts: .gitignore README.md package.json
- Loading branch information
Showing
352 changed files
with
98,104 additions
and
72 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,5 +1,5 @@ | ||
node_modules | ||
|
||
npm-debug.log | ||
|
||
*.swp | ||
node_modules/ | ||
node_modules/* |
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,69 +1,106 @@ | ||
Running a custom/latest Node[.js] version on RedHat's OpenShift PaaS | ||
==================================================================== | ||
This git repository is a sample Node application along with the | ||
"orchestration" bits to help you run the latest or a custom version | ||
of Node on RedHat's OpenShift PaaS. | ||
#MEAN-Seed | ||
|
||
##To install | ||
|
||
Selecting a Node version to install/use | ||
--------------------------------------- | ||
npm install | ||
|
||
To select the version of Node.js that you want to run, just edit or add | ||
a version to the .openshift/markers/NODEJS_VERSION file. | ||
##To run | ||
|
||
Example: To install Node.js version 0.9.1, you can run: | ||
$ echo -e "0.9.1\n" >> .openshift/markers/NODEJS_VERSION | ||
npm start | ||
|
||
##To populate Mongo | ||
GET /api/beers/populate | ||
|
||
The action_hooks in this application will use that NODEJS_VERSION marker | ||
file to download and extract that Node version if it is available on | ||
nodejs.org and will automatically set the paths up to use the node/npm | ||
binaries from that install directory. | ||
##A API | ||
|
||
See: .openshift/action_hooks/ for more details. | ||
> GET /api/beers | ||
> GET /api/beers/populate | ||
> GET /api/beers/\_id/:id | ||
> POST /api/beers/ | ||
> PUT /api/beers/\_id/:id | ||
> DELETE /api/beers/\_id/:id | ||
Note: The last non-blank line in the .openshift/markers/NODEJS_VERSION | ||
file.determines the version it will install. | ||
|
||
MEAN-seed is based in Angular Express Seed, you can see more about below. | ||
|
||
Okay, now onto how can you get a custom Node.js version running | ||
on OpenShift. | ||
# Angular Express Seed | ||
|
||
Start an awesome app with AngularJS on the front, Express + Node on the back. This project is an | ||
application skeleton for a typical [AngularJS](http://angularjs.org/) web app for those who want | ||
to use Node to serve their app. | ||
|
||
Steps to get a custom Node.js version running on OpenShift | ||
---------------------------------------------------------- | ||
The seed contains angular libraries, test libraries and a bunch of scripts all preconfigured for | ||
instant web development gratification. Just clone the repo (or download the zip/tarball) and | ||
you're ready to develop your application. | ||
|
||
Create an account at http://openshift.redhat.com/ | ||
The seed app shows how to wire together Angular client-side components with Express on the server. | ||
It also illustrates writing angular partials/views with the Jade templating library. | ||
|
||
Create a namespace, if you haven't already do so | ||
_Note: Although Jade supports interpolation, you should be doing that mostly on the client. Mixing | ||
server and browser templating will convolute your app. Instead, use Jade as a syntactic sugar for | ||
HTML, and let AngularJS take care of interpolation on the browser side._ | ||
|
||
rhc domain create <yournamespace> | ||
## How to use angular-express-seed | ||
|
||
Create a nodejs-0.6 application (you can name it anything via -a) | ||
Clone the angular-express-seed repository, run `npm install` to grab the dependencies, and start hacking! | ||
|
||
rhc app create -a palinode -t nodejs-0.6 | ||
### Running the app | ||
|
||
Add this `github nodejs-custom-version-openshift` repository | ||
Runs like a typical node app: | ||
|
||
cd palinode | ||
git remote add upstream -m master git://github.com/openshift/nodejs-custom-version-openshift.git | ||
git pull -s recursive -X theirs upstream master | ||
node app.js | ||
|
||
Optionally, specify the custom version of Node.js you want to run with | ||
(Default is v0.8.9). | ||
If you want to more later version of Node (example v0.9.1), you can change | ||
to that by just writing it to the end of the NODEJS_VERSION file and | ||
committing that change. | ||
### Running tests | ||
|
||
echo "0.9.1" >> .openshift/markers/NODEJS_VERSION | ||
git commit . -m 'use Node version 0.9.1' | ||
Coming soon! | ||
|
||
Then push the repo to OpenShift | ||
### Receiving updates from upstream | ||
|
||
git push | ||
Just fetch the changes and merge them into your project with git. | ||
|
||
That's it, you can now checkout your application at: | ||
|
||
http://palinode-$yournamespace.rhcloud.com | ||
( See env @ http://palinode-$yournamespace.rhcloud.com/env ) | ||
## Directory Layout | ||
|
||
app.js --> app config | ||
package.json --> for npm | ||
public/ --> all of the files to be used in on the client side | ||
css/ --> css files | ||
app.css --> default stylesheet | ||
img/ --> image files | ||
js/ --> javascript files | ||
app.js --> declare top-level app module | ||
controllers.js --> application controllers | ||
directives.js --> custom angular directives | ||
filters.js --> custom angular filters | ||
services.js --> custom angular services | ||
lib/ --> angular and 3rd party JavaScript libraries | ||
angular/ | ||
angular.js --> the latest angular js | ||
angular.min.js --> the latest minified angular js | ||
angular-*.js --> angular add-on modules | ||
version.txt --> version number | ||
routes/ | ||
api.js --> route for serving JSON | ||
index.js --> route for serving HTML pages and partials | ||
views/ | ||
index.jade --> main page for app | ||
layout.jade --> doctype, title, head boilerplate | ||
partials/ --> angular view partials (partial jade templates) | ||
partial1.jade | ||
partial2.jade | ||
|
||
|
||
|
||
## Example App | ||
|
||
A simple [blog](https://github.com/btford/angular-express-blog) based on this seed. | ||
|
||
|
||
## Contact | ||
|
||
For more information on AngularJS please check out http://angularjs.org/ | ||
For more on Express and Jade, http://expressjs.com/ and http://jade-lang.com/ are | ||
your friends. | ||
|
||
## License | ||
MIT |
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,74 @@ | ||
|
||
/** | ||
* Module dependencies | ||
*/ | ||
|
||
var express = require('express'), | ||
bodyParser = require('body-parser'), | ||
methodOverride = require('method-override'), | ||
errorHandler = require('errorhandler'), | ||
morgan = require('morgan'), | ||
routes = require('./routes'), | ||
partials = require('./routes/partials'), | ||
expose = require('./routes/expose'), | ||
db = require('./models/db'), | ||
http = require('http'), | ||
path = require('path'); | ||
|
||
var app = module.exports = express(); | ||
|
||
var api = {}; | ||
api.name = require('./routes/api/name'); | ||
api.beers = require('./routes/api/beers'); | ||
|
||
/** | ||
* Configuration | ||
*/ | ||
|
||
// all environments | ||
app.set('port', process.env.PORT || 3000); | ||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'jade'); | ||
app.use(morgan('dev')); | ||
app.use(bodyParser.urlencoded({extended: true})); | ||
app.use(bodyParser.json()); | ||
app.use(methodOverride()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
var env = process.env.NODE_ENV || 'development'; | ||
|
||
// development only | ||
if (env === 'development') { | ||
app.use(errorHandler()); | ||
} | ||
|
||
// production only | ||
if (env === 'production') { | ||
// TODO | ||
} | ||
|
||
|
||
/** | ||
* Routes | ||
*/ | ||
|
||
// serve index | ||
app.use('/', routes); | ||
|
||
// server view partials | ||
app.use('/partials', partials); | ||
app.use('/expose', expose); | ||
|
||
// JSON API | ||
app.use('/api/beers', api.beers); | ||
app.use('/api/name', api.name); | ||
|
||
// redirect all others to the index (HTML5 history) | ||
app.get('*', function(req, res, next) { | ||
res.render('index'); | ||
}); | ||
|
||
|
||
|
||
module.exports = 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 @@ | ||
#!/usr/bin/env node | ||
var debug = require('debug')('express'); | ||
var app = require('../app'); | ||
|
||
app.set('port', process.env.PORT || 3000); | ||
|
||
var server = app.listen(app.get('port'), function() { | ||
debug('Express server listening on port ' + server.address().port); | ||
}); |
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,87 @@ | ||
var Beer = require('../../models/beer'); | ||
var http = require('http'); | ||
var msg = ''; | ||
|
||
module.exports = { | ||
create: function(req, res, cb){ | ||
var dados = req.body; | ||
var model = new Beer(dados); | ||
model.save(function (err, data) { | ||
cb(err, data, res); | ||
}); | ||
}, | ||
retrieve: function(req, res, cb){ | ||
Beer.find({}, function (err, data) { | ||
cb(err, data, res); | ||
}); | ||
}, | ||
findOneBy_Id: function(req, res, cb){ | ||
var id = req.params.id; | ||
var query = {_id: id}; | ||
|
||
Beer.findOne(query, function (err, data) { | ||
cb(err, data, res); | ||
}); | ||
}, | ||
findOneById: function(req, res, cb){ | ||
var id = req.params.id; | ||
var query = {id: id}; | ||
|
||
Beer.findOne(query, function (err, data) { | ||
cb(err, data, res); | ||
}); | ||
}, | ||
findOneByName: function(req, res, cb){ | ||
var name = req.params.name; | ||
var query = {name: name}; | ||
|
||
Beer.findOne(query, function (err, data) { | ||
cb(err, data, res); | ||
}); | ||
}, | ||
update: function(req, res, cb){ | ||
var id = req.params.id; | ||
var query = {_id: id}; | ||
var mod = req.body; | ||
delete mod._id; | ||
Beer.update(query, mod, function (err, data) { | ||
cb(err, data, res); | ||
}); | ||
}, | ||
delete: function(req, res, cb){ | ||
var id = req.params.id; | ||
var query = {_id: id}; | ||
|
||
Beer.remove(query, function(err, data) { | ||
cb(err, data, res); | ||
}); | ||
}, | ||
populate: function(req, res, cb){ | ||
var url = 'http://api.openbeerdatabase.com/v1/beers.json'; | ||
// res.send(url); | ||
http.get(url, function(response){ | ||
var body = ''; | ||
response.setEncoding('utf8'); | ||
response.on('data', function(chunk){ | ||
body += chunk; | ||
}); | ||
response.on('end', function () { | ||
var list = JSON.parse(body).beers; | ||
Beer.create(list, function (err) { | ||
if (err){ | ||
res.json(err); | ||
} | ||
res.json(list); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,53 @@ | ||
var Beer = require('../models/beer'); | ||
var msg = ''; | ||
|
||
module.exports = { | ||
renderList: function(req, res, cb){ | ||
var msg = 'Listagem completa'; | ||
var view = 'beers/list'; | ||
var query = {}; | ||
Beer.find(query, function (err, data) { | ||
cb(err, data, res, view, msg); | ||
}); | ||
}, | ||
renderCreate: function(req, res, cb){ | ||
var msg = 'Cadastro de cerveja'; | ||
var view = 'beers/create'; | ||
cb(null, null, res, view, msg); | ||
}, | ||
renderShow: function(req, res, cb){ | ||
var msg = 'Consulta completa'; | ||
var view = 'beers/show'; | ||
var id = req.params.id; | ||
var query = {_id: id}; | ||
Beer.findOne(query, function (err, data) { | ||
cb(err, data, res, view, msg); | ||
}); | ||
}, | ||
renderEdit: function(req, res, cb){ | ||
var msg = 'Alteração de cerveja'; | ||
var view = 'beers/edit'; | ||
var id = req.params.id; | ||
var query = {_id: id}; | ||
Beer.findOne(query, function (err, data) { | ||
cb(err, data, res, view, msg); | ||
}); | ||
}, | ||
renderRemove: function(req, res, cb){ | ||
var msg = 'Remoção de cerveja'; | ||
var view = 'beers/remove'; | ||
var id = req.params.id; | ||
var query = {_id: id}; | ||
Beer.findOne(query, function (err, data) { | ||
cb(err, data, res, view, msg); | ||
}); | ||
} | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.