qa: Make some crappy hacks to let sveltekit work with baseurl
This commit is contained in:
parent
0e19b59452
commit
5560a526b1
41
qa/static.go
41
qa/static.go
@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
@ -19,15 +20,33 @@ var (
|
|||||||
indexTmpl []byte
|
indexTmpl []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
func getIndexHtml(w io.Writer, file io.Reader) {
|
func getIndexHtml(w io.Writer, file io.Reader) []byte {
|
||||||
var err error
|
if indexTmpl, err := ioutil.ReadAll(file); err != nil {
|
||||||
if indexTmpl, err = ioutil.ReadAll(file); err != nil {
|
|
||||||
log.Println("Cannot read whole index.html: ", err)
|
log.Println("Cannot read whole index.html: ", err)
|
||||||
|
return nil
|
||||||
} else {
|
} 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])
|
||||||
}
|
|
||||||
|
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)
|
w.Write(indexTmpl)
|
||||||
|
return indexTmpl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveOrReverse(forced_url string, baseURL string) func(c *gin.Context) {
|
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 {
|
} else {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
getIndexHtml(c.Writer, file)
|
indexTmpl = getIndexHtml(c.Writer, file)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.Writer.Write(indexTmpl)
|
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 {
|
} else {
|
||||||
http.FileServer(Assets).ServeHTTP(c.Writer, c.Request)
|
http.FileServer(Assets).ServeHTTP(c.Writer, c.Request)
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,11 @@
|
|||||||
|
|
||||||
export let activemenu = "";
|
export let activemenu = "";
|
||||||
$: {
|
$: {
|
||||||
const path = $page.url.pathname.split("/");
|
const path = $page.url.href.substr(document.baseURI.length-1).split("/");
|
||||||
if (path.length > 1) {
|
if (path.length > 1) {
|
||||||
activemenu = path[1];
|
activemenu = path[1];
|
||||||
|
} else {
|
||||||
|
activemenu = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Icon,
|
|
||||||
Spinner,
|
Spinner,
|
||||||
} from 'sveltestrap';
|
} from 'sveltestrap';
|
||||||
|
|
||||||
@ -77,9 +76,6 @@
|
|||||||
<Spinner size="sm" />
|
<Spinner size="sm" />
|
||||||
{:else if $exercicesIdx[todo.id_exercice]}
|
{:else if $exercicesIdx[todo.id_exercice]}
|
||||||
{$exercicesIdx[todo.id_exercice].title}
|
{$exercicesIdx[todo.id_exercice].title}
|
||||||
{#if $exercicesIdx[todo.id_exercice].wip}
|
|
||||||
<Icon name="cone-striped" />
|
|
||||||
{/if}
|
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Icon,
|
|
||||||
Spinner,
|
Spinner,
|
||||||
} from 'sveltestrap';
|
} from 'sveltestrap';
|
||||||
|
|
||||||
@ -84,9 +83,6 @@
|
|||||||
<Spinner size="sm" />
|
<Spinner size="sm" />
|
||||||
{:else}
|
{:else}
|
||||||
{$exercicesIdx[todo.id_exercice].title}
|
{$exercicesIdx[todo.id_exercice].title}
|
||||||
{#if $exercicesIdx[todo.id_exercice].wip}
|
|
||||||
<Icon name="cone-striped" />
|
|
||||||
{/if}
|
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -1,2 +1 @@
|
|||||||
export const ssr = false;
|
export const ssr = false;
|
||||||
export const prerender = true;
|
|
||||||
|
@ -6,9 +6,6 @@ const config = {
|
|||||||
adapter: adapt({
|
adapter: adapt({
|
||||||
fallback: 'index.html'
|
fallback: 'index.html'
|
||||||
}),
|
}),
|
||||||
paths: {
|
|
||||||
// base: '{{.urlbase}}',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user