Skip to content

Commit

Permalink
Remove hard-coded host name from SPA js files.
Browse files Browse the repository at this point in the history
Issue MIDU-192
  • Loading branch information
Gavric-Sava committed Apr 6, 2022
1 parent 43033a4 commit 4836b7b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
9 changes: 5 additions & 4 deletions assets/js/author.js
Original file line number Diff line number Diff line change
@@ -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));
Expand Down Expand Up @@ -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;

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

Expand Down Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions assets/js/book.js
Original file line number Diff line number Diff line change
@@ -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));
Expand Down Expand Up @@ -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;

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

Expand Down Expand Up @@ -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';
Expand Down
9 changes: 0 additions & 9 deletions config/database.php

This file was deleted.

0 comments on commit 4836b7b

Please sign in to comment.