File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ var logger = require('morgan');
66var indexRouter = require ( './routes/index' ) ;
77var usersRouter = require ( './routes/users' ) ;
88
9+ var apiResponse = require ( './helpers/apiResponse' ) ;
10+
911var app = express ( ) ;
1012
1113app . use ( logger ( 'dev' ) ) ;
@@ -17,4 +19,9 @@ app.use(express.static(path.join(__dirname, 'public')));
1719app . use ( '/' , indexRouter ) ;
1820app . use ( '/users' , usersRouter ) ;
1921
22+ // throw 404 if URL not found
23+ app . get ( "*" , function ( req , res ) {
24+ return apiResponse . notFoundResponse ( res , 'Page not found' ) ;
25+ } ) ;
26+
2027module . exports = app ;
Original file line number Diff line number Diff line change 1+ exports . successResponse = function ( res , msg ) {
2+ var data = {
3+ status : 1 ,
4+ message : msg
5+ }
6+ return res . status ( 200 ) . json ( data ) ;
7+ } ;
8+
9+ exports . successResponseWithData = function ( res , msg , data ) {
10+ var data = {
11+ status : 1 ,
12+ message : msg ,
13+ data : data
14+ }
15+ return res . status ( 200 ) . json ( data ) ;
16+ }
17+
18+ exports . ErrorResponse = function ( res , msg ) {
19+ var data = {
20+ status : 0 ,
21+ message : msg ,
22+ }
23+ return res . status ( 500 ) . json ( data ) ;
24+ }
25+
26+ exports . notFoundResponse = function ( res , msg ) {
27+ var data = {
28+ status : 0 ,
29+ message : msg ,
30+ }
31+ return res . status ( 404 ) . json ( data ) ;
32+ }
You can’t perform that action at this time.
0 commit comments