Fix bug where UV would stop working after new page
This commit is contained in:
parent
922ef15f5f
commit
4b267c6a59
6 changed files with 59 additions and 36 deletions
4
index.js
4
index.js
|
|
@ -25,6 +25,10 @@ app.use(express.urlencoded({
|
|||
app.use("/", express.static('dist/client/'));
|
||||
app.use(ssrHandler);
|
||||
|
||||
app.get('*', function(req, res){
|
||||
res.status(200).sendFile("404.html", {root: path.resolve("dist/client")});
|
||||
});
|
||||
|
||||
server.on("request", (req, res) => {
|
||||
if (bareServer.shouldRoute(req)) {
|
||||
bareServer.routeRequest(req, res);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"start": "node ."
|
||||
"start": "node .",
|
||||
"build": "astro build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/check": "^0.4.0",
|
||||
|
|
|
|||
|
|
@ -1,19 +1,13 @@
|
|||
<script src="/uv/uv.bundle.js" is:inline></script>
|
||||
<script src="/uv.config.js" is:inline></script>
|
||||
<script>
|
||||
declare global {
|
||||
interface Window {
|
||||
__uv$config: any;
|
||||
}
|
||||
}
|
||||
const form = document.querySelector('form')!;
|
||||
const input = document.querySelector('input')!;
|
||||
|
||||
window.navigator.serviceWorker.register('/sw.js', {
|
||||
<script src="/uv/uv.bundle.js" transition:persist is:inline></script>
|
||||
<script src="/uv.config.js" transition:persist is:inline></script>
|
||||
<script transition:persist>
|
||||
var form = document.querySelector('form');
|
||||
var input = document.querySelector('input');
|
||||
window.navigator.serviceWorker.register('/sw.js', {
|
||||
scope: window.__uv$config.prefix
|
||||
})
|
||||
})
|
||||
|
||||
form.addEventListener('submit', (event) => {
|
||||
form.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
let url = input.value.trim();
|
||||
if (!isUrl(url)) url = 'https://www.google.com/search?q=' + url;
|
||||
|
|
@ -21,11 +15,13 @@ form.addEventListener('submit', (event) => {
|
|||
let loadingContent = document.getElementById('loading-content');
|
||||
if (loadingContent) loadingContent.style.opacity = "1";
|
||||
|
||||
window.location.href = window.__uv$config.prefix + window.__uv$config.encodeUrl(url);
|
||||
});
|
||||
console.log("here")
|
||||
|
||||
function isUrl(val = ''){
|
||||
window.location.href = window.__uv$config.prefix + window.__uv$config.encodeUrl(url);
|
||||
});
|
||||
|
||||
function isUrl(val = ''){
|
||||
if (/^http(s?):\/\//.test(val) || val.includes('.') && val.substr(0, 1) !== ' ') return true;
|
||||
return false;
|
||||
};
|
||||
</script>
|
||||
};
|
||||
</script>
|
||||
|
|
@ -52,4 +52,12 @@ body {
|
|||
::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
.main-content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
height: 60vh;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
21
src/pages/404.astro
Normal file
21
src/pages/404.astro
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
import Footer from "../components/Footer.astro";
|
||||
import Header from "../components/Header.astro";
|
||||
import Layout from "../layouts/Layout.astro";
|
||||
|
||||
---
|
||||
|
||||
<Layout title="404 | Alu">
|
||||
<Header></Header>
|
||||
<div class="main-content error-page">
|
||||
<h1>404!</h1>
|
||||
<p>The content you have requested could not be found!</p>
|
||||
</div>
|
||||
<Footer></Footer>
|
||||
</Layout>
|
||||
|
||||
<style>
|
||||
.error-page {
|
||||
color: white
|
||||
}
|
||||
</style>
|
||||
|
|
@ -7,7 +7,7 @@ import UVRegistrar from '../components/UVRegistrar.astro';
|
|||
|
||||
<Layout title="Alu's Unblocker">
|
||||
<Header></Header>
|
||||
<div class="main-content" data-barba="container" data-barba-namespace="home">
|
||||
<div class="main-content">
|
||||
<h1 id="title-text" class="title-text">Welcome to Alu</h1>
|
||||
<form>
|
||||
<input placeholder="Enter a URL...">
|
||||
|
|
@ -15,18 +15,11 @@ import UVRegistrar from '../components/UVRegistrar.astro';
|
|||
<p id="loading-content">Loading Content...</p>
|
||||
</div>
|
||||
<UVRegistrar></UVRegistrar>
|
||||
|
||||
<Footer></Footer>
|
||||
</Layout>
|
||||
|
||||
<style>
|
||||
.main-content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
height: 60vh;
|
||||
}
|
||||
form {
|
||||
width: 30%;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue