qa: Make some crappy hacks to let sveltekit work with baseurl

This commit is contained in:
nemunaire 2022-11-07 04:57:00 +01:00
parent 0e19b59452
commit 5560a526b1
6 changed files with 39 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import (
"io"
"io/ioutil"
"log"
"mime"
"net/http"
"net/url"
"path"
@ -19,15 +20,33 @@ var (
indexTmpl []byte
)
func getIndexHtml(w io.Writer, file io.Reader) {
var err error
if indexTmpl, err = ioutil.ReadAll(file); err != nil {
func getIndexHtml(w io.Writer, file io.Reader) []byte {
if indexTmpl, err := ioutil.ReadAll(file); err != nil {
log.Println("Cannot read whole index.html: ", err)
return nil
} else {
indexTmpl = bytes.Replace(indexTmpl, []byte("{{.urlbase}}"), []byte(path.Clean(path.Join(BaseURL+"/", "nuke"))[:len(path.Clean(path.Join(BaseURL+"/", "nuke")))-4]), -1)
}
good_base := []byte(path.Clean(path.Join(BaseURL+"/", "nuke"))[:len(path.Clean(path.Join(BaseURL+"/", "nuke")))-4])
w.Write(indexTmpl)
indexTmpl = bytes.Replace(
bytes.Replace(
bytes.Replace(
indexTmpl,
[]byte("{{.urlbase}}"),
good_base,
-1,
),
[]byte("\"/_app/"),
append([]byte("\""), append(good_base, '_', 'a', 'p', 'p', '/')...),
-1,
),
[]byte("paths: {\"base\":\""),
append([]byte("paths: {\"base\":\""), good_base[:len(good_base)-1]...),
-1,
)
w.Write(indexTmpl)
return indexTmpl
}
}
func serveOrReverse(forced_url string, baseURL string) func(c *gin.Context) {
@ -75,11 +94,21 @@ func serveOrReverse(forced_url string, baseURL string) func(c *gin.Context) {
} else {
defer file.Close()
getIndexHtml(c.Writer, file)
indexTmpl = getIndexHtml(c.Writer, file)
}
} else {
c.Writer.Write(indexTmpl)
}
} else if baseURL != "/" {
if file, err := Assets.Open(c.Request.URL.Path); err != nil {
http.FileServer(Assets).ServeHTTP(c.Writer, c.Request)
} else {
defer file.Close()
c.Writer.Header().Add("Content-Type", mime.TypeByExtension(path.Ext(c.Request.URL.Path)))
getIndexHtml(c.Writer, file)
}
} else {
http.FileServer(Assets).ServeHTTP(c.Writer, c.Request)
}

View File

@ -26,9 +26,11 @@
export let activemenu = "";
$: {
const path = $page.url.pathname.split("/");
const path = $page.url.href.substr(document.baseURI.length-1).split("/");
if (path.length > 1) {
activemenu = path[1];
} else {
activemenu = "";
}
}
</script>

View File

@ -2,7 +2,6 @@
import { goto } from '$app/navigation';
import {
Icon,
Spinner,
} from 'sveltestrap';
@ -77,9 +76,6 @@
<Spinner size="sm" />
{:else if $exercicesIdx[todo.id_exercice]}
{$exercicesIdx[todo.id_exercice].title}
{#if $exercicesIdx[todo.id_exercice].wip}
<Icon name="cone-striped" />
{/if}
{/if}
</td>
<td>

View File

@ -2,7 +2,6 @@
import { goto } from '$app/navigation';
import {
Icon,
Spinner,
} from 'sveltestrap';
@ -84,9 +83,6 @@
<Spinner size="sm" />
{:else}
{$exercicesIdx[todo.id_exercice].title}
{#if $exercicesIdx[todo.id_exercice].wip}
<Icon name="cone-striped" />
{/if}
{/if}
</td>
</tr>

View File

@ -1,2 +1 @@
export const ssr = false;
export const prerender = true;

View File

@ -6,9 +6,6 @@ const config = {
adapter: adapt({
fallback: 'index.html'
}),
paths: {
// base: '{{.urlbase}}',
},
}
};