Skip to content

Commit bcdda73

Browse files
authored
Merge pull request #15 from iolufemi/bugFix/forbiddenStatusCode
Bug fix/forbidden status code
2 parents 9b1f25c + 1d83c68 commit bcdda73

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/iolufemi/Express-REST-API-Generator.svg?branch=dev)](https://travis-ci.org/iolufemi/Express-REST-API-Generator) [![codecov](https://codecov.io/gh/iolufemi/Express-REST-API-Generator/branch/master/graph/badge.svg)](https://codecov.io/gh/iolufemi/Express-REST-API-Generator) [![Documentation Status](https://readthedocs.org/projects/api-template/badge/?version=latest)](http://api-template.readthedocs.io/en/latest/?badge=latest)
44

5-
Express REST API Generator is an Express Based API skeleton. A template for starting projects with express as an API. This project can be used for creating a RESTful API using Node JS, Express as the framework and Mongoose to interact with a MongoDB instance. Mocha is also used for running unit tests in the project.
5+
Express REST API Generator is an Express Based API skeleton. A template for starting projects with express as an API. This project can be used for creating a RESTful API using Node JS, Express as the framework, Mongoose to interact with a MongoDB instance and Sequelize for support of SQL compatible databases. Mocha is also used for running unit tests in the project.
66

77
The resulting API from this project is a JSON REST API which will respond to requests over HTTP. REST Clients can, therefore, connect to the resulting REST server.
88

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-cayman

routes/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ req.cacheKey = key;
194194

195195
};
196196

197+
router.use(helmet());
198+
router.use(cors());
199+
router.options('*', cors());
200+
router.use(bodyParser.urlencoded({ extended: false }));
201+
router.use(bodyParser.json());
202+
router.use(bodyParser.raw());
203+
router.use(bodyParser.text());
204+
197205
// Log requests here
198206
router.use(function(req,res,next){
199207
var ipAddress = req.ip;
@@ -222,14 +230,6 @@ queue.create('logRequest', reqLog)
222230
log.info(reqLog);
223231
next();
224232
});
225-
226-
router.use(helmet());
227-
router.use(cors());
228-
router.options('*', cors());
229-
router.use(bodyParser.urlencoded({ extended: false }));
230-
router.use(bodyParser.json());
231-
router.use(bodyParser.raw());
232-
router.use(bodyParser.text());
233233
// load response handlers
234234
router.use(response);
235235
// Watch for encrypted requests
@@ -258,7 +258,7 @@ router.use(expressValidator());
258258
if(config.noFrontendCaching === 'yes'){
259259
router.use(helmet.noCache());
260260
}else{
261-
router.use(router._APICache);
261+
router.use(router._APICache);
262262
}
263263

264264
router.get('/', function (req, res) {

services/response/forbidden.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ module.exports = function(data, message){
2222
}
2323

2424
if(data){
25-
this.status(503).json({status: 'error', data: data, message: message ? message : 'forbidden'});
25+
this.status(403).json({status: 'error', data: data, message: message ? message : 'forbidden'});
2626
}else{
27-
this.status(503).json({status: 'error', message: message ? message : 'forbidden'});
27+
this.status(403).json({status: 'error', message: message ? message : 'forbidden'});
2828
}
2929
};

test/services/response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('#Response service test', function(){
160160
it('should be forbidden', function(done){
161161
agent.
162162
get('/forbidden')
163-
.expect(503,done);
163+
.expect(403,done);
164164
});
165165
it('should not be found', function(done){
166166
agent.

0 commit comments

Comments
 (0)