Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some cosmetic changes around router #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/config/db.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
HOST: "us-cdbr-iron-east-02.cleardb.net",
USER: "b7e24378878xxx",
PASSWORD: "0200exxx",
DB: "heroku_7643ec736354xxx"
HOST: "<DB_HOST_NAME>",
USER: "<DB_USER_NAME>",
PASSWORD: "<DB_PASSWORD>",
DB: "<DB_NAME>"
};
31 changes: 16 additions & 15 deletions app/routes/customer.routes.js
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions app/routes/index.routes.js
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 5 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require("express");
const bodyParser = require("body-parser");
const router = require('./app/routes/index.routes.js')

const app = express();

Expand All @@ -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;
Expand Down