diff --git a/assets/js/index.js b/assets/js/index.js index 2af5424..a9ab17e 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -1,4 +1,4 @@ - +const PORT = process.env.PORT; $("#add_user").submit(function(event){ @@ -17,7 +17,7 @@ $("#update_user").submit(function(event){ var request = { - "url" : `http://localhost:3000/api/users/${data.id}`, + "url" : `http://localhost:${PORT}/api/users/${data.id}`, "method" : "PUT", "data" : data } @@ -34,7 +34,7 @@ if(window.location.pathname == "/"){ var id = $(this).attr("data-id") var request = { - "url" : `http://localhost:3000/api/users/${id}`, + "url" : `http://localhost:${PORT}/api/users/${id}`, "method" : "DELETE" } diff --git a/server/services/render.js b/server/services/render.js index 22068b7..d5befe0 100644 --- a/server/services/render.js +++ b/server/services/render.js @@ -1,9 +1,10 @@ const axios = require('axios'); +const PORT = process.env.PORT; exports.homeRoutes = (req, res) => { // Make a get request to /api/users - axios.get('http://localhost:3000/api/users') + axios.get(`http://localhost:${PORT}/api/users`) .then(function(response){ res.render('index', { users : response.data }); }) @@ -19,7 +20,7 @@ exports.add_user = (req, res) =>{ } exports.update_user = (req, res) =>{ - axios.get('http://localhost:3000/api/users', { params : { id : req.query.id }}) + axios.get(`http://localhost:${PORT}/api/users`, { params : { id : req.query.id }}) .then(function(userdata){ res.render("update_user", { user : userdata.data}) })