diff --git a/Dockerfile b/Dockerfile index 995942b..cb5d1b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ COPY . . RUN npm run build:server # RUN ls -la # RUN ls -laR dist/ -CMD ["node", "dist/app.js"] +CMD ["npm", "run", "serve:prod"] # ----------------------------------------------------------------- # # EOF diff --git a/client/src/lib/requests.js b/client/src/lib/requests.js new file mode 100644 index 0000000..6390828 --- /dev/null +++ b/client/src/lib/requests.js @@ -0,0 +1,14 @@ +import axios from 'axios' + +const apiPath = '/api/author' + +function getAuthors () { + axios.get(`${apiPath}`) + .then((res) => { + return (res.data) + }) +} + +export default { + getAuthors +} diff --git a/client/src/routes/api/authors/[slug].js b/client/src/routes/api/authors/[slug].js deleted file mode 100644 index 0373bdb..0000000 --- a/client/src/routes/api/authors/[slug].js +++ /dev/null @@ -1,34 +0,0 @@ -import db from '../../../json/db.js' - -const authors = db.authors - -export async function get (request) { - try { - const bid = request.params.slug - const book = await authors.find(({ id }) => id === bid) - return { - status: 200, - body: book - } - } catch (err) { - return { - status: 500, - body: { - error: 'A server error occured: ', - type: '' + err - } - } - } -} - -export async function del (request) { - const bid = parseInt(request.params.slug) - const ret = authors.findIndex(({ id }) => id === bid) - if (ret >= 0) { - authors.splice(ret, 1) - } - return { - status: 200, - body: { i: ret } - } -} diff --git a/client/src/routes/api/authors/index.js b/client/src/routes/api/authors/index.js deleted file mode 100644 index 630d8c8..0000000 --- a/client/src/routes/api/authors/index.js +++ /dev/null @@ -1,29 +0,0 @@ -import db from '../../../json/db.js' - -const authors = db.authors -const books = db.books - -function newId () { - const newId = books.reduce((a, c) => { return (c.id > a) ? c.id : a }, 0) - - return 1 + newId -} - -export async function get (request) { - return { - status: 200, - body: authors - } -} - -export async function put (request) { - const author = JSON.parse(request.body) - author.id = newId() - authors.push(author) - return { - status: 200, - body: { - status: 'Success' - } - } -} diff --git a/client/src/routes/api/books/[slug].js b/client/src/routes/api/books/[slug].js deleted file mode 100644 index 06a5954..0000000 --- a/client/src/routes/api/books/[slug].js +++ /dev/null @@ -1,35 +0,0 @@ - -import db from '../../../json/db.js' - -const books = db.books - -export async function get (request) { - try { - const bid = request.params.slug - const book = await books.find(({ id }) => id === bid) - return { - status: 200, - body: book - } - } catch (err) { - return { - status: 500, - body: { - error: 'A server error occured: ', - type: '' + err - } - } - } -} - -export async function del (request) { - const bid = parseInt(request.params.slug) - const ret = books.findIndex(({ id }) => id === bid) - if (ret >= 0) { - books.splice(ret, 1) - } - return { - status: 200, - body: { i: ret } - } -} diff --git a/client/src/routes/api/books/index.js b/client/src/routes/api/books/index.js deleted file mode 100644 index f2c804b..0000000 --- a/client/src/routes/api/books/index.js +++ /dev/null @@ -1,10 +0,0 @@ -import db from '../../../json/db.js' - -const books = db.books - -export async function get (request) { - return { - status: 200, - body: books - } -} diff --git a/client/src/routes/authors.svelte b/client/src/routes/authors.svelte index 6332ff4..977db6c 100644 --- a/client/src/routes/authors.svelte +++ b/client/src/routes/authors.svelte @@ -1,100 +1,111 @@ @@ -106,34 +117,52 @@ - + - + Name - + Bio - - + {#each authors as author} - - - {author.name} - - - {author.bio} - - - Edit - Delete - - + + + {author.name} + + + {author.bio} + + + Edit + Delete + + {/each} @@ -142,27 +171,30 @@ - - {#if updateopen}Edit Author{:else}Add a new Author{/if} + {#if updateopen}Edit Author{:else}Add a new Author{/if} Name: - - + + Bio: - + {#if updateopen} - - Update author - + Update author {:else} - - Add author - + Add author {/if} - - Cancel - + Cancel diff --git a/client/src/routes/books.svelte b/client/src/routes/books.svelte index e333e1c..f9680a4 100644 --- a/client/src/routes/books.svelte +++ b/client/src/routes/books.svelte @@ -1,10 +1,33 @@