Skip to content

Commit 763a28b

Browse files
authored
perf(app): simplify + update web app (#2)
1 parent 4b31c2b commit 763a28b

File tree

7 files changed

+334
-106
lines changed

7 files changed

+334
-106
lines changed

app/index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1">
6+
<title>StackBlitz Zip API</title>
7+
<style>body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;margin:2rem}</style>
8+
</head>
9+
<body>
10+
<h1>StackBlitz Zip API</h1>
11+
<p>Replace <code>stackblitz.com</code> with <code>stackblitz.zip</code> in any StackBlitz URL.</p>
12+
<ul>
13+
<script server>
14+
const links = [
15+
'/edit/nuxt-starter-k7spa3r4',
16+
'/edit/vitejs-vite-starter',
17+
].map(path => new URL(path, $REQUEST.url).href)
18+
</script>
19+
<? for (const link of links) { ?>
20+
<li><a href="<?= link ?>" target="_blank" rel="noopener noreferrer"><?= link ?></a></li>
21+
<? } ?>
22+
</ul>
23+
<p>The <code>.zip</code> extension is optional but recommended for clarity.</p>
24+
<footer style="margin-top:2rem;border-top:1px solid #eee;padding-top:1rem;font-size:0.9rem;color:#555">
25+
<p>Star on GitHub: <a href="https://github.com/danielroe/stackblitz.zip" target="_blank" rel="noopener noreferrer">danielroe/stackblitz.zip</a></p>
26+
</footer>
27+
</body>
28+
</html>

app/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"preview": "node .output/server/index.mjs"
1414
},
1515
"dependencies": {
16-
"h3": "2.0.1-rc.5",
17-
"nitro": "latest",
16+
"nitro": "npm:[email protected]",
1817
"stackblitz-zip": "workspace:*",
1918
"vite": "^7.2.0"
2019
}

app/routes/index.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import { defineEventHandler, getRouterParam, HTTPError } from 'h3'
1+
import { defineHandler, HTTPError } from 'nitro/h3'
22
import { downloadToBlob, parseUrl } from 'stackblitz-zip'
33

4-
export default defineEventHandler(async (event) => {
5-
const path = getRouterParam(event, 'path')
6-
7-
if (!path) {
8-
throw new HTTPError({
9-
status: 400,
10-
statusText: 'Missing path',
11-
})
12-
}
4+
export default defineHandler(async (event) => {
5+
const { pathname } = event.url
6+
if (pathname === '/')
7+
return // render index.html
138

149
// Convert stackblitz.zip URL to stackblitz.com URL
15-
const stackblitzUrl = `https://stackblitz.com/${path.replace(/\.zip$/, '')}`
10+
const stackblitzUrl = `https://stackblitz.com/${pathname.replace(/^\/|\.zip$/g, '')}`
1611

1712
// Validate it's a valid StackBlitz edit URL
1813
if (!stackblitzUrl.match(/stackblitz\.com\/edit\/[^/?#]+/)) {

app/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
nitro({
77
config: {
88
routeRules: {
9-
'/': { prerender: true },
9+
'/': { isr: true },
1010
},
1111
},
1212
}),

knip.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"stackblitz-zip"
77
],
88
"entry": [
9-
"routes/**"
9+
"server.ts"
1010
]
1111
}
1212
}

0 commit comments

Comments
 (0)