Compare commits

...

11 commits

Author SHA1 Message Date
Owski
d0d2148099
Merge pull request #36 from MovByte/aero
Improve how aero is used
2024-10-02 17:25:41 -05:00
Ryan Wilson
432d151a31 Fix outdated file name in import 2024-09-24 12:15:55 -04:00
Ryan Wilson
3c3dc996e4 Add better error handling to aero 2024-09-24 12:06:35 -04:00
Ryan Wilson
97d305ddcc Omit the NPM version tag to automatically get the latest 2024-09-24 11:52:13 -04:00
Ryan Wilson
42af80da9c Route AeroSandbox as well 2024-09-24 11:45:30 -04:00
Ryan Wilson
bb725fcf54 Improve how aero is used 2024-09-24 11:39:37 -04:00
Ryan Wilson
24d80b34e0 Fix bash variable declaration for $AERO_PATH 2024-09-23 21:15:47 -04:00
proudparrot2
72eb44dbf2
Merge pull request #35 from MovByte/aero
Make UV the default proxy
2024-09-23 13:37:30 -05:00
Ryan Wilson
9c06b4925b Make UV the default proxy 2024-09-23 14:35:41 -04:00
proudparrot2
025b64b75b
Merge pull request #34 from MovByte/aero
Add aero support and a switcher backend
2024-09-23 13:20:47 -05:00
Ryan Wilson
15514e2862 Add aero support and a switcher backend 2024-09-23 14:16:16 -04:00
10 changed files with 195 additions and 26 deletions

3
.gitignore vendored
View file

@ -2,6 +2,7 @@
# dependencies # dependencies
/node_modules /node_modules
package-lock.json
/.pnp /.pnp
.pnp.js .pnp.js
.yarn/install-state.gz .yarn/install-state.gz
@ -34,3 +35,5 @@ yarn-error.log*
# typescript # typescript
*.tsbuildinfo *.tsbuildinfo
next-env.d.ts next-env.d.ts
# TODO: Add UV public build files here (not the UV config file)

View file

@ -19,6 +19,8 @@
"@radix-ui/react-toast": "^1.1.5", "@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "^1.0.7", "@radix-ui/react-tooltip": "^1.0.7",
"@tomphttp/bare-server-node": "^2.0.3", "@tomphttp/bare-server-node": "^2.0.3",
"aero-proxy": "^0.0.3",
"aero-sandbox": "^0.0.1",
"class-variance-authority": "^0.7.0", "class-variance-authority": "^0.7.0",
"clsx": "^2.1.0", "clsx": "^2.1.0",
"framer-motion": "^11.0.25", "framer-motion": "^11.0.25",

51
public/sw.js Normal file
View file

@ -0,0 +1,51 @@
// Example: aero with other proxies in a SW switcher design
// Constants
/**
* @type {string}
*/
const dirToAeroConfig = "/aero/";
/**
* @type {string}
*/
const dirToUvConfigAndBundle = "/uv/";
importScripts(`${dirToAeroConfig}config.aero.js`);
importScripts(aeroConfig.bundle["bare-mux"]);
importScripts(aeroConfig.bundle.handle);
importScripts(`${dirToUvConfigAndBundle}uv.bundle.js`);
importScripts(`${dirToUvConfigAndBundle}uv.config.js`);
importScripts(__uv$config.sw);
importScripts(`${dirToAeroConfig}/extras/handleWithExtras.js`);
const aeroHandlerWithExtras = patchAeroHandler(handle);
const uv = new UVServiceWorker();
addEventListener("install", skipWaiting);
// Switching
let chosenProxy = defaultProxy;
addEventListener("message", event => {
if ("type" in event.data && event.data.type === "changeDefault") {
const possibleChosenProxy = event.data.data;
if (isValidProxy(possibleChosenProxy))
chosenProxy = possibleChosenProxy;
else {
console.log(
`Fatal error: tried to set the default proxy, but the proxy to be set isn't supported: ${chosenProxy}`
);
}
}
});
addEventListener("fetch", ev => {
if (ev.request.url.startsWith(__uv$config.prefix))
return ev.respondWith(uv.fetch(ev));
if (routeAero(ev)) return ev.respondWith(aeroHandlerWithExtras(ev));
});
function isValidProxy(proxy) {
return ["aero", "uv"].includes(proxy);
}

View file

@ -0,0 +1,29 @@
import fs from 'fs'
import { notFound } from 'next/navigation'
import { NextRequest } from 'next/server'
export async function GET(_req: NextRequest, { params }: { params: { aero: string } }) {
const requestedFile = params.aero
if (requestedFile === 'aero.config.js') {
const file = fs.readFileSync(process.cwd() + `/src/lib/aero/${requestedFile}`)
const fileBlob = new Blob([file])
return new Response(fileBlob, {
headers: {
'Content-Type': 'application/javascript'
}
})
} else {
try {
const res = await fetch(`https://unpkg.com/browse/aero-proxy/dist/${requestedFile}`)
const file = await res.text()
const fileBlob = new Blob([file])
return new Response(fileBlob, {
headers: {
'Content-Type': 'application/javascript'
}
})
} catch {
notFound()
}
}
}

View file

@ -0,0 +1,19 @@
import fs from 'fs'
import { notFound } from 'next/navigation'
import { NextRequest } from 'next/server'
export async function GET(_req: NextRequest, { params }: { params: { aero: string } }) {
const requestedFile = params.aero
try {
const res = await fetch(`https://unpkg.com/browse/aero-proxy/extras/${requestedFile}`)
const file = await res.text()
const fileBlob = new Blob([file])
return new Response(fileBlob, {
headers: {
'Content-Type': 'application/javascript'
}
})
} catch {
notFound()
}
}

View file

@ -0,0 +1,18 @@
import { notFound } from 'next/navigation'
import { NextRequest } from 'next/server'
export async function GET(_req: NextRequest, { params }: { params: { aeroSandbox: string } }) {
const requestedFile = params.aeroSandbox
try {
const res = await fetch(`https://unpkg.com/browse/aero-sandbox/dist/${requestedFile}`)
const file = await res.text()
const fileBlob = new Blob([file])
return new Response(fileBlob, {
headers: {
'Content-Type': 'application/javascript'
}
})
} catch {
notFound()
}
}

View file

@ -22,6 +22,17 @@ export default function Route({ params }: { params: { route: string[] } }) {
useEffect(() => { useEffect(() => {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
if (localStorage.getItem("defaultProxy") === "aero")
navigator.serviceWorker
.register('/aero/sw.aero.js', {
scope: '/aero/service'
})
.then(() => {
if (ref.current) {
ref.current.src = '/aero/service/' + formatSearch(atob(decodeURIComponent(route)))
}
})
else {
navigator.serviceWorker navigator.serviceWorker
.register('/uv/sw.js', { .register('/uv/sw.js', {
scope: '/uv/service' scope: '/uv/service'
@ -32,6 +43,7 @@ export default function Route({ params }: { params: { route: string[] } }) {
} }
}) })
} }
}
}, []) }, [])
function triggerShortcut() { function triggerShortcut() {
@ -39,6 +51,7 @@ export default function Route({ params }: { params: { route: string[] } }) {
if (!ref.current || !ref.current.contentWindow) return if (!ref.current || !ref.current.contentWindow) return
const contentWindow = ref.current.contentWindow as ContentWindow const contentWindow = ref.current.contentWindow as ContentWindow
if (!('__uv$location' in contentWindow)) return if (!('__uv$location' in contentWindow)) return
if (!('aeroConfig' in contentWindow)) return
const shortcuts: any[] = store('shortcuts') const shortcuts: any[] = store('shortcuts')
if (shortcuts.some((value) => value.url == contentWindow.__uv$location.href)) { if (shortcuts.some((value) => value.url == contentWindow.__uv$location.href)) {

View file

@ -4,8 +4,8 @@ import { NextRequest } from 'next/server'
export async function GET(_req: NextRequest, { params }: { params: { uv: string } }) { export async function GET(_req: NextRequest, { params }: { params: { uv: string } }) {
const requestedFile = params.uv const requestedFile = params.uv
if (requestedFile === 'uv.config.js' || requestedFile === 'sw.js') { if (requestedFile === 'aero.config.js') {
const file = fs.readFileSync(process.cwd() + `/src/lib/uv/${requestedFile}`) const file = fs.readFileSync(process.cwd() + `/src/lib/aero/${requestedFile}`)
const fileBlob = new Blob([file]) const fileBlob = new Blob([file])
return new Response(fileBlob, { return new Response(fileBlob, {
headers: { headers: {
@ -14,7 +14,7 @@ export async function GET(_req: NextRequest, { params }: { params: { uv: string
}) })
} else { } else {
try { try {
const res = await fetch(`https://unpkg.com/@titaniumnetwork-dev/ultraviolet@2.0.0/dist/${requestedFile}`) const res = await fetch(`https://unpkg.com/browse/aero-proxy@0.0.3/dist/${requestedFile}`)
const file = await res.text() const file = await res.text()
const fileBlob = new Blob([file]) const fileBlob = new Blob([file])
return new Response(fileBlob, { return new Response(fileBlob, {

View file

@ -0,0 +1,48 @@
/** @import { Config } from "aero-proxy" */
const escapeKeyword = "_";
/**
* @type {Config}
*/
self.aeroConfig = {
bc: new BareMux(),
prefix: "/aero/service",
pathToInitialSW: "/sw.js",
bundles: {
"bare-mux": "/aero/BareMux.aero.js",
handle: "/aero/sw.aero.js",
sandbox: "/aero/sandbox/sandbox.aero.js"
},
aeroPathFilter: path =>
Object.values(self.config.bundles).find(bundlePath =>
path.startsWith(bundlePath)
) === null ||
path.startsWith("/tests/") ||
path.startsWith("/baremux") ||
path.startsWith("/epoxy/") ||
!path.startsWith(aeroConfig.prefix),
searchParamOptions: {
referrerPolicy: {
escapeKeyword,
searchParam: "passthroughReferrerPolicy"
},
isModule: {
escapeKeyword,
searchParam: "isModule"
},
integrity: {
escapeKeyword,
searchParam: "integrity"
}
},
cacheKey: "httpCache",
dynamicConfig: {
dbName: "aero",
id: "update"
},
//urlEncoder: __uv$config.urlEncoder,
//urlDecoder: __uv$config.urlDecoder,
urlEncoder: url => url,
urlDecoder: url => url
};

View file

@ -1,14 +0,0 @@
/*global UVServiceWorker,__uv$config*/
/*
* Stock service worker script.
* Users can provide their own sw.js if they need to extend the functionality of the service worker.
* Ideally, this will be registered under the scope in uv.config.js so it will not need to be modified.
* However, if a user changes the location of uv.bundle.js/uv.config.js or sw.js is not relative to them, they will need to modify this script locally.
*/
importScripts('/uv/uv.bundle.js');
importScripts('/uv/uv.config.js');
importScripts(__uv$config.sw || '/uv/uv.sw.js');
const sw = new UVServiceWorker();
self.addEventListener('fetch', (event) => event.respondWith(sw.fetch(event)));