Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>StackBlitz Zip API</title>
<style>body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;margin:2rem}</style>
</head>
<body>
<h1>StackBlitz Zip API</h1>
<p>Replace <code>stackblitz.com</code> with <code>stackblitz.zip</code> in any StackBlitz URL.</p>
<ul>
<script server>
const links = [
'/edit/nuxt-starter-k7spa3r4',
'/edit/vitejs-vite-starter',
].map(path => new URL(path, $REQUEST.url).href)
</script>
<? for (const link of links) { ?>
<li><a href="<?= link ?>" target="_blank" rel="noopener noreferrer"><?= link ?></a></li>
<? } ?>
</ul>
<p>The <code>.zip</code> extension is optional but recommended for clarity.</p>
<footer style="margin-top:2rem;border-top:1px solid #eee;padding-top:1rem;font-size:0.9rem;color:#555">
<p>Star on GitHub: <a href="https://github.com/danielroe/stackblitz.zip" target="_blank" rel="noopener noreferrer">danielroe/stackblitz.zip</a></p>
</footer>
</body>
</html>
3 changes: 1 addition & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"preview": "node .output/server/index.mjs"
},
"dependencies": {
"h3": "2.0.1-rc.5",
"nitro": "latest",
"nitro": "npm:nitro-nightly@3.0.1-20251105-152910-c0ee44bf",
"stackblitz-zip": "workspace:*",
"vite": "^7.2.0"
}
Expand Down
13 changes: 0 additions & 13 deletions app/routes/index.ts

This file was deleted.

17 changes: 6 additions & 11 deletions app/routes/[...path].ts → app/server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { defineEventHandler, getRouterParam, HTTPError } from 'h3'
import { defineHandler, HTTPError } from 'nitro/h3'
import { downloadToBlob, parseUrl } from 'stackblitz-zip'

export default defineEventHandler(async (event) => {
const path = getRouterParam(event, 'path')

if (!path) {
throw new HTTPError({
status: 400,
statusText: 'Missing path',
})
}
export default defineHandler(async (event) => {
const { pathname } = event.url
if (pathname === '/')
return // render index.html

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

// Validate it's a valid StackBlitz edit URL
if (!stackblitzUrl.match(/stackblitz\.com\/edit\/[^/?#]+/)) {
Expand Down
2 changes: 1 addition & 1 deletion app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
nitro({
config: {
routeRules: {
'/': { prerender: true },
'/': { isr: true },
},
},
}),
Expand Down
2 changes: 1 addition & 1 deletion knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"stackblitz-zip"
],
"entry": [
"routes/**"
"server.ts"
]
}
}
Expand Down
Loading