Fix bug where UV would stop working after new page

This commit is contained in:
wearrrrr 2024-01-09 14:28:36 -06:00
parent 922ef15f5f
commit 4b267c6a59
6 changed files with 59 additions and 36 deletions

View file

@ -25,6 +25,10 @@ app.use(express.urlencoded({
app.use("/", express.static('dist/client/')); app.use("/", express.static('dist/client/'));
app.use(ssrHandler); app.use(ssrHandler);
app.get('*', function(req, res){
res.status(200).sendFile("404.html", {root: path.resolve("dist/client")});
});
server.on("request", (req, res) => { server.on("request", (req, res) => {
if (bareServer.shouldRoute(req)) { if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res); bareServer.routeRequest(req, res);

View file

@ -3,7 +3,8 @@
"type": "module", "type": "module",
"version": "0.0.1", "version": "0.0.1",
"scripts": { "scripts": {
"start": "node ." "start": "node .",
"build": "astro build"
}, },
"dependencies": { "dependencies": {
"@astrojs/check": "^0.4.0", "@astrojs/check": "^0.4.0",

View file

@ -1,31 +1,27 @@
<script src="/uv/uv.bundle.js" is:inline></script> <script src="/uv/uv.bundle.js" transition:persist is:inline></script>
<script src="/uv.config.js" is:inline></script> <script src="/uv.config.js" transition:persist is:inline></script>
<script> <script transition:persist>
declare global { var form = document.querySelector('form');
interface Window { var input = document.querySelector('input');
__uv$config: any; window.navigator.serviceWorker.register('/sw.js', {
} scope: window.__uv$config.prefix
} })
const form = document.querySelector('form')!;
const input = document.querySelector('input')!;
window.navigator.serviceWorker.register('/sw.js', { form.addEventListener('submit', (event) => {
scope: window.__uv$config.prefix event.preventDefault();
})
form.addEventListener('submit', (event) => {
event.preventDefault();
let url = input.value.trim(); let url = input.value.trim();
if (!isUrl(url)) url = 'https://www.google.com/search?q=' + url; if (!isUrl(url)) url = 'https://www.google.com/search?q=' + url;
else if (!(url.startsWith('https://') || url.startsWith('http://'))) url = 'http://' + url; else if (!(url.startsWith('https://') || url.startsWith('http://'))) url = 'http://' + url;
let loadingContent = document.getElementById('loading-content'); let loadingContent = document.getElementById('loading-content');
if (loadingContent) loadingContent.style.opacity = "1"; 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);
if (/^http(s?):\/\//.test(val) || val.includes('.') && val.substr(0, 1) !== ' ') return true; });
return false;
}; function isUrl(val = ''){
</script> if (/^http(s?):\/\//.test(val) || val.includes('.') && val.substr(0, 1) !== ' ') return true;
return false;
};
</script>

View file

@ -52,4 +52,12 @@ body {
::-webkit-scrollbar { ::-webkit-scrollbar {
display: none; display: none;
} }
.main-content {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100%;
height: 60vh;
}
</style> </style>

21
src/pages/404.astro Normal file
View 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>

View file

@ -7,26 +7,19 @@ import UVRegistrar from '../components/UVRegistrar.astro';
<Layout title="Alu's Unblocker"> <Layout title="Alu's Unblocker">
<Header></Header> <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> <h1 id="title-text" class="title-text">Welcome to Alu</h1>
<form> <form>
<input placeholder="Enter a URL..."> <input placeholder="Enter a URL...">
</form> </form>
<p id="loading-content">Loading Content...</p> <p id="loading-content">Loading Content...</p>
</div> </div>
<UVRegistrar></UVRegistrar> <UVRegistrar></UVRegistrar>
<Footer></Footer> <Footer></Footer>
</Layout> </Layout>
<style> <style>
.main-content {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100%;
height: 60vh;
}
form { form {
width: 30%; width: 30%;
} }