From 4836b7bbdcbef881e9cfa97a59d37799095fef73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sava=20Gavri=C4=87?= Date: Wed, 6 Apr 2022 11:39:10 +0200 Subject: [PATCH] Remove hard-coded host name from SPA js files. Issue MIDU-192 --- assets/js/author.js | 9 +++++---- assets/js/book.js | 8 ++++---- config/database.php | 9 --------- 3 files changed, 9 insertions(+), 17 deletions(-) delete mode 100644 config/database.php diff --git a/assets/js/author.js b/assets/js/author.js index 4b3f835..dcb0fc5 100644 --- a/assets/js/author.js +++ b/assets/js/author.js @@ -1,5 +1,6 @@ function requestAuthorList() { - const response = fetch('http://bookstore.test/spa/authors'); + console.log(location.protocol); + const response = fetch(location.protocol + '//' + location.host + '/spa/authors'); response.then((response) => processResponse(response, (response) => { response.text().then((body) => { generateHTMLAuthorList(JSON.parse(body)); @@ -255,7 +256,7 @@ function generateHTMLAuthorCreate() { } }; - httpRequest.open('POST', 'http://bookstore.test/spa/authors/create'); + httpRequest.open('POST', location.protocol + '//' + location.host + '/spa/authors/create'); const first_name_param = 'first_name=' + document.getElementsByName('first_name')[0].value; const last_name_param = 'last_name=' + document.getElementsByName('last_name')[0].value; @@ -295,7 +296,7 @@ function generateHTMLAuthorEdit(id, firstname, lastname) { } }; - httpRequest.open('POST', 'http://bookstore.test/spa/authors/edit/' + id); + httpRequest.open('POST', location.protocol + '//' + location.host + '/spa/authors/edit/' + id); const first_name_param = 'first_name=' + document.getElementsByName('first_name')[0].value; const last_name_param = 'last_name=' + document.getElementsByName('last_name')[0].value; @@ -362,7 +363,7 @@ function generateHTMLAuthorDelete(id, firstname, lastname) { } }; - httpRequest.open('POST', 'http://bookstore.test/spa/authors/delete/' + id); + httpRequest.open('POST', location.protocol + '//' + location.host + '/spa/authors/delete/' + id); httpRequest.send(); }); form.method = 'post'; diff --git a/assets/js/book.js b/assets/js/book.js index 30ca66b..4c0d65b 100644 --- a/assets/js/book.js +++ b/assets/js/book.js @@ -1,6 +1,6 @@ function requestBookList(author_id) { clearContent(); - const response = fetch(`http://bookstore.test/spa/authors/${author_id}/books`); + const response = fetch(location.protocol + '//' + location.host + `/spa/authors/${author_id}/books`); response.then((response) => processResponse(response, (response) => { response.text().then((body) => { generateHTMLBookList(JSON.parse(body)); @@ -234,7 +234,7 @@ function generateHTMLBookCreate() { } }; - httpRequest.open('POST', `http://bookstore.test/spa/authors/${history.state.author_id}/books/create`); + httpRequest.open('POST', location.protocol + '//' + location.host + `/spa/authors/${history.state.author_id}/books/create`); const title_param = 'title=' + document.getElementsByName('title')[0].value; const year_param = 'year=' + document.getElementsByName('year')[0].value; @@ -274,7 +274,7 @@ function generateHTMLBookEdit(id, title, year, author_id) { } }; - httpRequest.open('POST', `http://bookstore.test/spa/authors/${author_id}/books/edit/${id}`); + httpRequest.open('POST', location.protocol + '//' + location.host + `/spa/authors/${author_id}/books/edit/${id}`); const title_param = 'title=' + document.getElementsByName('title')[0].value; const year_param = 'year=' + document.getElementsByName('year')[0].value; @@ -340,7 +340,7 @@ function generateHTMLBookDelete(id, title, year, author_id) { } }; - httpRequest.open('POST', `http://bookstore.test/spa/authors/${author_id}/books/delete/${id}`); + httpRequest.open('POST', location.protocol + '//' + location.host + `/spa/authors/${author_id}/books/delete/${id}`); httpRequest.send(); }); form.method = 'post'; diff --git a/config/database.php b/config/database.php deleted file mode 100644 index fcdf2be..0000000 --- a/config/database.php +++ /dev/null @@ -1,9 +0,0 @@ - 'mysql', -// 'host' => 'localhost', - 'host' => 'database', - 'db_name' => 'bookstore_db', - 'username' => 'bookstore_user', - 'password' => 'password' -); \ No newline at end of file