Serve compiled front from the same application
also add embedded build for production
This commit is contained in:
5
front/frontend.go
Normal file
5
front/frontend.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package front
|
||||
|
||||
import "io/fs"
|
||||
|
||||
var Frontend fs.FS
|
||||
11
front/frontend_dev.go
Normal file
11
front/frontend_dev.go
Normal file
@@ -0,0 +1,11 @@
|
||||
//go:build !embed
|
||||
|
||||
package front
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Frontend = os.DirFS("./dist")
|
||||
}
|
||||
19
front/frontend_embed.go
Normal file
19
front/frontend_embed.go
Normal file
@@ -0,0 +1,19 @@
|
||||
//go:build embed
|
||||
|
||||
package front
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
//go:embed dist
|
||||
var frontend embed.FS
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
Frontend, err = fs.Sub(frontend, "dist")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite --host",
|
||||
"dev": "vite build --watch",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint . --fix",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 750 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
@@ -1,13 +1,11 @@
|
||||
import { useAuthStore } from './auth.store.js'
|
||||
|
||||
const baseUrl = "http://localhost:8080"
|
||||
|
||||
export function getInventaireImagePathOrDefault(path) {
|
||||
return getImagePathOrGivenDefault(path, "../../defaultinventairebook.png")
|
||||
return getImagePathOrGivenDefault(path, "../../image/defaultinventairebook.png")
|
||||
}
|
||||
|
||||
export function getImagePathOrDefault(path) {
|
||||
return getImagePathOrGivenDefault(path, "../defaultbook.png")
|
||||
return getImagePathOrGivenDefault(path, "../image/defaultbook.png")
|
||||
}
|
||||
|
||||
export function getImagePathOrGivenDefault(path, defaultpath) {
|
||||
@@ -16,7 +14,7 @@ export function getImagePathOrGivenDefault(path, defaultpath) {
|
||||
} else if (path.startsWith("https://")) {
|
||||
return path;
|
||||
} else {
|
||||
return baseUrl + path;
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,78 +36,78 @@ function useFetch(data, error, url) {
|
||||
|
||||
export function getMyBooks(data, error, arg, limit, offset) {
|
||||
const queryParams = new URLSearchParams({limit: limit, offset: offset});
|
||||
return useFetch(data, error, baseUrl + '/mybooks/' + arg + "?" + queryParams.toString());
|
||||
return useFetch(data, error, '/ws/mybooks/' + arg + "?" + queryParams.toString());
|
||||
}
|
||||
|
||||
export function getSearchBooks(data, error, searchterm, lang, searchInventaire, limit, offset) {
|
||||
const queryParams = new URLSearchParams({lang: lang, inventaire: searchInventaire, limit: limit, offset: offset});
|
||||
return useFetch(data, error, baseUrl + '/search/' + encodeURIComponent(searchterm) + "?" + queryParams.toString());
|
||||
return useFetch(data, error, '/ws/search/' + encodeURIComponent(searchterm) + "?" + queryParams.toString());
|
||||
}
|
||||
|
||||
export function getInventaireEditionBooks(data, error, inventaireId, lang, limit, offset) {
|
||||
const queryParams = new URLSearchParams({lang: lang, limit: limit, offset: offset});
|
||||
return useFetch(data, error, baseUrl + '/inventaire/books/' + encodeURIComponent(inventaireId) + "?" + queryParams.toString());
|
||||
return useFetch(data, error, '/ws/inventaire/books/' + encodeURIComponent(inventaireId) + "?" + queryParams.toString());
|
||||
}
|
||||
|
||||
export function getAuthor(data, error, id) {
|
||||
return useFetch(data, error, baseUrl + '/author/' + id);
|
||||
return useFetch(data, error, '/ws/author/' + id);
|
||||
}
|
||||
|
||||
export function getAuthorBooks(data, error, id, limit, offset) {
|
||||
const queryParams = new URLSearchParams({limit: limit, offset: offset});
|
||||
return useFetch(data, error, baseUrl + '/author/' + id + "/books" + "?" + queryParams.toString());
|
||||
return useFetch(data, error, '/ws/author/' + id + "/books" + "?" + queryParams.toString());
|
||||
}
|
||||
|
||||
export function getBook(data, error, id) {
|
||||
return useFetch(data, error, baseUrl + '/book/' + id);
|
||||
return useFetch(data, error, '/ws/book/' + id);
|
||||
}
|
||||
|
||||
export function postBook(book) {
|
||||
return genericPayloadCall('/book', book.value, 'POST')
|
||||
return genericPayloadCall('/ws/book', book.value, 'POST')
|
||||
}
|
||||
|
||||
export async function postImportBook(id, language) {
|
||||
return genericPayloadCall('/importbook', {inventaireid: id, lang: language}, 'POST');
|
||||
return genericPayloadCall('/ws/importbook', {inventaireid: id, lang: language}, 'POST');
|
||||
}
|
||||
|
||||
export async function putReadBook(bookId) {
|
||||
return genericPayloadCall('/book/' + bookId + "/read", {read: true}, 'PUT')
|
||||
return genericPayloadCall('/ws/book/' + bookId + "/read", {read: true}, 'PUT')
|
||||
}
|
||||
|
||||
export async function putUnreadBook(bookId) {
|
||||
return genericPayloadCall('/book/' + bookId + "/read", {read: false}, 'PUT')
|
||||
return genericPayloadCall('/ws/book/' + bookId + "/read", {read: false}, 'PUT')
|
||||
}
|
||||
|
||||
export async function putEndReadDate(bookId, enddate) {
|
||||
return genericPayloadCall('/book/' + bookId + "/read", {read: true, endDate: enddate}, 'PUT')
|
||||
return genericPayloadCall('/ws/book/' + bookId + "/read", {read: true, endDate: enddate}, 'PUT')
|
||||
}
|
||||
|
||||
export async function putEndReadDateUnset(bookId) {
|
||||
return genericPayloadCall('/book/' + bookId + "/read", {read: true, endDate: "null"}, 'PUT')
|
||||
return genericPayloadCall('/ws/book/' + bookId + "/read", {read: true, endDate: "null"}, 'PUT')
|
||||
}
|
||||
|
||||
export async function putStartReadDateUnset(bookId) {
|
||||
return genericPayloadCall('/book/' + bookId + "/startread", {startDate: "null"}, 'PUT')
|
||||
return genericPayloadCall('/ws/book/' + bookId + "/startread", {startDate: "null"}, 'PUT')
|
||||
}
|
||||
|
||||
export async function putStartReadDate(bookId, startdate) {
|
||||
return genericPayloadCall('/book/' + bookId + "/startread", {startDate: startdate}, 'PUT')
|
||||
return genericPayloadCall('/ws/book/' + bookId + "/startread", {startDate: startdate}, 'PUT')
|
||||
}
|
||||
|
||||
export async function putWantReadBook(bookId, payload) {
|
||||
return genericPayloadCall('/book/' + bookId + "/wantread", payload, 'PUT')
|
||||
return genericPayloadCall('/ws/book/' + bookId + "/wantread", payload, 'PUT')
|
||||
}
|
||||
|
||||
export async function putRateBook(bookId, payload) {
|
||||
return genericPayloadCall('/book/' + bookId + "/rate", payload, 'PUT')
|
||||
return genericPayloadCall('/ws/book/' + bookId + "/rate", payload, 'PUT')
|
||||
}
|
||||
|
||||
export function postLogin(user) {
|
||||
return genericPostCallNoAuth('/auth/login', user.value)
|
||||
return genericPostCallNoAuth('/ws/auth/login', user.value)
|
||||
}
|
||||
|
||||
export function postSignUp(user) {
|
||||
return genericPostCallNoAuth('/auth/signup', user.value)
|
||||
return genericPostCallNoAuth('/ws/auth/signup', user.value)
|
||||
}
|
||||
|
||||
export function postImage(file) {
|
||||
@@ -117,7 +115,7 @@ export function postImage(file) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
if (user != null) {
|
||||
return fetch(baseUrl + "/upload/cover", {
|
||||
return fetch("/ws/upload/cover", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + user.token
|
||||
@@ -130,7 +128,7 @@ export function postImage(file) {
|
||||
}
|
||||
|
||||
export function genericPostCallNoAuth(apiRoute, object) {
|
||||
return fetch(baseUrl + apiRoute, {
|
||||
return fetch(apiRoute, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -143,7 +141,7 @@ export function genericPayloadCall(apiRoute, object, method) {
|
||||
const { user } = useAuthStore();
|
||||
|
||||
if (user != null) {
|
||||
return fetch(baseUrl + apiRoute, {
|
||||
return fetch(apiRoute, {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user