react-express-mongodb: rename server to backend
The goal here is to keep the same structure than the other examples. Also, considering that it has a "frontend" folder, the equivalent for the server should be "backend". Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
		
							parent
							
								
									e29f0d1c54
								
							
						
					
					
						commit
						be8875c9b6
					
				
					 16 changed files with 8 additions and 8 deletions
				
			
		
							
								
								
									
										38
									
								
								react-express-mongodb/backend/routes/index.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								react-express-mongodb/backend/routes/index.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| const express = require('express'); | ||||
| const serverResponses = require('../utils/helpers/server.responses'); | ||||
| const messages = require('../config/messages'); | ||||
| var {Todo} = require('../models/todos/todo.model'); | ||||
| 
 | ||||
| const routes = (app) => { | ||||
|     const router = express.Router(); | ||||
| 
 | ||||
|     router.post('/todos', (req,res)=>{ | ||||
|         var todo = new Todo({ | ||||
|             text: req.body.text | ||||
|         }); | ||||
| 
 | ||||
|         todo.save() | ||||
|             .then((result)=>{ | ||||
|                 serverResponses.sendSuccess(res,messages.SUCCESSFUL, result); | ||||
|             }) | ||||
|             .catch((e) => { | ||||
|                 serverResponses.sendError(res,messages.BAD_REQUEST,e) | ||||
|             }) | ||||
|     }); | ||||
| 
 | ||||
|     router.get('/', (req,res) => { | ||||
|         Todo.find({}, {__v:0}) | ||||
|             .then((todos)=>{ | ||||
|                 serverResponses.sendSuccess(res,messages.SUCCESSFUL, todos); | ||||
| 
 | ||||
|             }) | ||||
|             .catch((e) => { | ||||
|                 serverResponses.sendError(res,messages.BAD_REQUEST,e) | ||||
|             }) | ||||
|     }); | ||||
| 
 | ||||
|     //it's a prefix before api it is useful when you have many modules and you want to
 | ||||
|     //differentiate b/w each module you can use this technique
 | ||||
|     app.use('/api', router); | ||||
| }; | ||||
| module.exports = routes; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue