Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge branch '0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Aug 2, 2014
2 parents ba0a6a0 + b6cd10f commit 315024e
Show file tree
Hide file tree
Showing 48 changed files with 1,075 additions and 962 deletions.
49 changes: 49 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# EditorConfig is awesome: http://EditorConfig.org

# Howto with your editor:
# Sublime: https://github.com/sindresorhus/editorconfig-sublime

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[**]
end_of_line = lf
insert_final_newline = true

# Standard at: https://github.com/felixge/node-style-guide
[**.js, **.json]
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
max_line_length = 80
quote_type = single
curly_bracket_next_line = false
spaces_around_operators = true
space_after_control_statements = true
space_after_anonymous_functions = false
spaces_in_brackets = false

# https://github.com/jedmao/codepainter
[node_modules/**.js]
codepaint = false

# No Standard. Please document a standard if different from .js
[**.yml, **.html, **.css]
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

# No standard. Please document a standard if different from .js
[**.md]
indent_style = space

# Standard at:
[**.py]
indent_style = space
indent_size = 4

# Standard at:
[Makefile]
indent_style = tab
indent_size = 8
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
npm-debug.log
node_modules/
public/lib
public/dist
app/tests/coverage/
.bower-*/
.idea/
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM dockerfile/nodejs

MAINTAINER Matthias Luebken, matthias@catalyst-zero.com

WORKDIR /home/mean

# Install Mean.JS Prerequisites
RUN npm install -g grunt-cli
RUN npm install -g bower

# Install Mean.JS packages
ADD package.json /home/mean/package.json
RUN npm install

# Manually trigger bower. Why doesnt this work via npm install?
ADD .bowerrc /home/mean/.bowerrc
ADD bower.json /home/mean/bower.json
RUN bower install --config.interactive=false --allow-root

# Make everything available for start
ADD . /home/mean

# currently only works for development
ENV NODE_ENV development

# Port 3000 for server
# Port 35729 for livereload
EXPOSE 3000 35729
CMD ["grunt"]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ Your application should run on the 3000 port so in your browser just go to [http
That's it! your application should be running by now, to proceed with your development check the other sections in this documentation.
If you encounter any problem try the Troubleshooting section.

## Development and deployment With Docker

* Install [Docker](http://www.docker.com/)
* Install [Fig](https://github.com/orchardup/fig)

* Local development and testing with fig:
```bash
$ fig up
```

* Local development and testing with just Docker:
```bash
$ docker build -t mean .
$ docker run -p 27017:27017 -d --name db mongo
$ docker run -p 3000:3000 --link db:db_1 mean
$
```

* To enable live reload forward 35729 port and mount /app and /public as volumes:
```bash
$ docker run -p 3000:3000 -p 35729:35729 -v /Users/mdl/workspace/mean-stack/mean/public:/home/mean/public -v /Users/mdl/workspa/mean-stack/mean/app:/home/mean/app --link db:db_1 mean
```

## Getting Started With MEAN.JS
You have your application running but there are a lot of stuff to understand, we recommend you'll go over the [Offical Documentation](http://meanjs.org/docs.html).
In the docs we'll try to explain both general concepts of MEAN components and give you some guidelines to help you improve your development procees. We tried covering as many aspects as possible, and will keep update it by your request, you can also help us develop the documentation better by checking out the *gh-pages* branch of this repository.
Expand Down
43 changes: 10 additions & 33 deletions app/controllers/articles.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,10 @@
* Module dependencies.
*/
var mongoose = require('mongoose'),
errorHandler = require('./errors'),
Article = mongoose.model('Article'),
_ = require('lodash');

/**
* Get the error message from error object
*/
var getErrorMessage = function(err) {
var message = '';

if (err.code) {
switch (err.code) {
case 11000:
case 11001:
message = 'Article already exists';
break;
default:
message = 'Something went wrong';
}
} else {
for (var errName in err.errors) {
if (err.errors[errName].message) message = err.errors[errName].message;
}
}

return message;
};

/**
* Create a article
*/
Expand All @@ -40,8 +17,8 @@ exports.create = function(req, res) {

article.save(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(article);
Expand All @@ -66,8 +43,8 @@ exports.update = function(req, res) {

article.save(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(article);
Expand All @@ -83,8 +60,8 @@ exports.delete = function(req, res) {

article.remove(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(article);
Expand All @@ -98,8 +75,8 @@ exports.delete = function(req, res) {
exports.list = function(req, res) {
Article.find().sort('-created').populate('user', 'displayName').exec(function(err, articles) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(articles);
Expand All @@ -124,7 +101,7 @@ exports.articleByID = function(req, res, next, id) {
*/
exports.hasAuthorization = function(req, res, next) {
if (req.article.user.id !== req.user.id) {
return res.send(403, {
return res.status(403).send({
message: 'User is not authorized'
});
}
Expand Down
42 changes: 42 additions & 0 deletions app/controllers/errors.server.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

/**
* Get unique error field name
*/
var getUniqueErrorMessage = function(err) {
var output;

try {
var fieldName = err.err.substring(err.err.lastIndexOf('.$') + 2, err.err.lastIndexOf('_1'));
output = fieldName.charAt(0).toUpperCase() + fieldName.slice(1) + ' already exist';

} catch(ex) {
output = 'Unique field already exist';
}

return output;
};

/**
* Get the error message from error object
*/
exports.getErrorMessage = function(err) {
var message = '';

if (err.code) {
switch (err.code) {
case 11000:
case 11001:
message = getUniqueErrorMessage(err);
break;
default:
message = 'Something went wrong';
}
} else {
for (var errName in err.errors) {
if (err.errors[errName].message) message = err.errors[errName].message;
}
}

return message;
};
Loading

0 comments on commit 315024e

Please sign in to comment.