Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pomdtr/smallweb-preview-demo


https://github.com/pomdtr/smallweb-preview-demo

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# Preview URLs with Smallweb

All commit in this repository can be referenced by a preview URL.

Ex:

- main branch:
- 1st commit:
- PR branch:

## How does it work ?

```jsonc
// ~/.config/smallweb/config.json
{
"domains": {
"preview-demo-*.smallweb.run": "~/smallweb.run/preview-demo"
}
}
```

```ts
// ~/smallweb.run/preview-demo/main.ts

const repo = "pomdtr/smallweb-preview-url-demo";

export default {
async fetch(req: Request) {
const { hostname } = new URL(req.url);
const [subdomain] = hostname.split(".");
const ref = subdomain.split("-").pop();
const { default: handler } = await import(
`https://raw.githubusercontent.com/${repo}/${ref}/main.ts`
);

return handler.fetch(req);
},
};
```