Compare commits
11 commits
main
...
aero-archi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0d2148099 | ||
|
|
432d151a31 | ||
|
|
3c3dc996e4 | ||
|
|
97d305ddcc | ||
|
|
42af80da9c | ||
|
|
bb725fcf54 | ||
|
|
24d80b34e0 | ||
|
|
72eb44dbf2 | ||
|
|
9c06b4925b | ||
|
|
025b64b75b | ||
|
|
15514e2862 |
10 changed files with 195 additions and 26 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
# dependencies
|
||||
/node_modules
|
||||
package-lock.json
|
||||
/.pnp
|
||||
.pnp.js
|
||||
.yarn/install-state.gz
|
||||
|
|
@ -34,3 +35,5 @@ yarn-error.log*
|
|||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
# TODO: Add UV public build files here (not the UV config file)
|
||||
|
|
@ -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' || requestedFile === 'sw.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
|
||||
};
|
||||
|
|
@ -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)));
|
||||
Loading…
Add table
Reference in a new issue