Skip to content

Commit bac8819

Browse files
committed
update server
1 parent 0536d0f commit bac8819

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

app/server.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@ import { defineHandler, HTTPError } from 'nitro/h3'
22
import { downloadToBlob, parseUrl } from 'stackblitz-zip'
33

44
export default defineHandler(async (event) => {
5-
if (event.url.pathname === '/')
6-
return
7-
8-
const path = event.context.params!.path
9-
10-
if (!path) {
11-
throw new HTTPError({
12-
status: 400,
13-
statusText: 'Missing path',
14-
})
15-
}
5+
const { pathname } = event.url
6+
if (pathname === '/')
7+
return // render index.html
168

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

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

0 commit comments

Comments
 (0)