From 99c433a4dbd4f53d21127af4c6de71a3aeeb1cbf Mon Sep 17 00:00:00 2001 From: sandipsutariya Date: Fri, 18 Dec 2020 16:53:40 +0530 Subject: [PATCH 1/2] Removed Hardcoded value --- app/config/db.config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/config/db.config.js b/app/config/db.config.js index 02c172bd..c3f1f2ce 100644 --- a/app/config/db.config.js +++ b/app/config/db.config.js @@ -1,6 +1,6 @@ module.exports = { - HOST: "us-cdbr-iron-east-02.cleardb.net", - USER: "b7e24378878xxx", - PASSWORD: "0200exxx", - DB: "heroku_7643ec736354xxx" + HOST: "", + USER: "", + PASSWORD: "", + DB: "" }; From 1f488fa895a7b076d18f9148da3b729b3fc46870 Mon Sep 17 00:00:00 2001 From: ssutari Date: Sat, 19 Dec 2020 14:14:47 +0530 Subject: [PATCH 2/2] router added --- app/routes/customer.routes.js | 31 ++++++++++++++++--------------- app/routes/index.routes.js | 9 +++++++++ package.json | 1 + server.js | 6 +++++- 4 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 app/routes/index.routes.js diff --git a/app/routes/customer.routes.js b/app/routes/customer.routes.js index 2137e506..7d6a4314 100644 --- a/app/routes/customer.routes.js +++ b/app/routes/customer.routes.js @@ -1,21 +1,22 @@ -module.exports = app => { - const customers = require("../controllers/customer.controller.js"); +const router = require('express').Router(); +const customers = require("../controllers/customer.controller.js"); - // Create a new Customer - app.post("/customers", customers.create); +// Create a new Customer +router.post("/", customers.create); - // Retrieve all Customers - app.get("/customers", customers.findAll); +// Retrieve all Customers +router.get("/", customers.findAll); - // Retrieve a single Customer with customerId - app.get("/customers/:customerId", customers.findOne); +// Retrieve a single Customer with customerId +router.get("/:customerId", customers.findOne); - // Update a Customer with customerId - app.put("/customers/:customerId", customers.update); +// Update a Customer with customerId +router.put("/:customerId", customers.update); - // Delete a Customer with customerId - app.delete("/customers/:customerId", customers.delete); +// Delete a Customer with customerId +router.delete("/:customerId", customers.delete); - // Create a new Customer - app.delete("/customers", customers.deleteAll); -}; +// Create a new Customer +router.delete("/", customers.deleteAll); + +module.exports = router diff --git a/app/routes/index.routes.js b/app/routes/index.routes.js new file mode 100644 index 00000000..e584227a --- /dev/null +++ b/app/routes/index.routes.js @@ -0,0 +1,9 @@ +// To handle all routes from one file, making it more scalable + +const router = require('express').Router(); +const customerRoute = require('./customer.routes.js'); + +// Adding customer routes - can add more routes here +router.use('/customers', customerRoute); + +module.exports = router \ No newline at end of file diff --git a/package.json b/package.json index 4cfc6892..cdff84a2 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Node.js Restful CRUD API with Node.js, Express and MySQL", "main": "server.js", "scripts": { + "start":"node server.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [ diff --git a/server.js b/server.js index 45bf996d..ae12dbb9 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ const express = require("express"); const bodyParser = require("body-parser"); +const router = require('./app/routes/index.routes.js') const app = express(); @@ -14,7 +15,10 @@ app.get("/", (req, res) => { res.json({ message: "Welcome to bezkoder application." }); }); -require("./app/routes/customer.routes.js")(app); +//require("./app/routes/customer.routes.js")(app); +// Using router +app.use("/",router) + // set port, listen for requests const PORT = process.env.PORT || 3000;