commit
d0d2148099
10 changed files with 192 additions and 28 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -36,12 +36,4 @@ yarn-error.log*
|
|||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
# SW proxies - general
|
||||
public/aeroHandleSimple.js
|
||||
public/sw.js
|
||||
|
||||
# aero
|
||||
public/aero/
|
||||
**/aeroConfigBuild/
|
||||
|
||||
# TODO: Add UV public build files here (not the UV config file)
|
||||
8
deps.sh
8
deps.sh
|
|
@ -1,8 +0,0 @@
|
|||
# Your bash variables here
|
||||
$AERO_PATH="public/aero" # The directory where aero's files should be
|
||||
|
||||
./node_modules/aero-proxy/examples/install-aero.sh
|
||||
|
||||
curl https://raw.githubusercontent.com/vortexdeveloperlabs/sdk/refs/heads/main/aeroHandleSimple.js -o public/aeroHandleSimple.js
|
||||
cp ./node_modules/aero-proxy/examples/swWithSwitcher.js public/sw.js
|
||||
sed -i 's/const defaultProxy = "aero";/const defaultProxy = "uv";/' public/sw.js
|
||||
|
|
@ -19,6 +19,8 @@
|
|||
"@radix-ui/react-toast": "^1.1.5",
|
||||
"@radix-ui/react-tooltip": "^1.0.7",
|
||||
"@tomphttp/bare-server-node": "^2.0.3",
|
||||
"aero-proxy": "^0.0.3",
|
||||
"aero-sandbox": "^0.0.1",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.1.0",
|
||||
"framer-motion": "^11.0.25",
|
||||
|
|
|
|||
51
public/sw.js
Normal file
51
public/sw.js
Normal 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);
|
||||
}
|
||||
29
src/app/aero/[aero]/route.ts
Normal file
29
src/app/aero/[aero]/route.ts
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/app/aero/extras/[extras]/route.ts
Normal file
19
src/app/aero/extras/[extras]/route.ts
Normal 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()
|
||||
}
|
||||
}
|
||||
18
src/app/aero/sandbox/[sandbox]/route.ts
Normal file
18
src/app/aero/sandbox/[sandbox]/route.ts
Normal 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()
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,17 @@ export default function Route({ params }: { params: { route: string[] } }) {
|
|||
|
||||
useEffect(() => {
|
||||
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
|
||||
.register('/uv/sw.js', {
|
||||
scope: '/uv/service'
|
||||
|
|
@ -32,6 +43,7 @@ export default function Route({ params }: { params: { route: string[] } }) {
|
|||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
function triggerShortcut() {
|
||||
|
|
@ -39,6 +51,7 @@ export default function Route({ params }: { params: { route: string[] } }) {
|
|||
if (!ref.current || !ref.current.contentWindow) return
|
||||
const contentWindow = ref.current.contentWindow as ContentWindow
|
||||
if (!('__uv$location' in contentWindow)) return
|
||||
if (!('aeroConfig' in contentWindow)) return
|
||||
const shortcuts: any[] = store('shortcuts')
|
||||
|
||||
if (shortcuts.some((value) => value.url == contentWindow.__uv$location.href)) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import { NextRequest } from 'next/server'
|
|||
|
||||
export async function GET(_req: NextRequest, { params }: { params: { uv: string } }) {
|
||||
const requestedFile = params.uv
|
||||
if (requestedFile === 'uv.config.js') {
|
||||
const file = fs.readFileSync(process.cwd() + `/src/lib/uv/${requestedFile}`)
|
||||
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: {
|
||||
|
|
@ -14,7 +14,7 @@ export async function GET(_req: NextRequest, { params }: { params: { uv: string
|
|||
})
|
||||
} else {
|
||||
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 fileBlob = new Blob([file])
|
||||
return new Response(fileBlob, {
|
||||
|
|
|
|||
48
src/lib/aero/aero.config.js
Normal file
48
src/lib/aero/aero.config.js
Normal 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
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue