Skip to content

Commit

Permalink
update example apps
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Jan 9, 2025
1 parent eefc3dd commit 5ab9bf4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/.smallweb/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"domain": "smallweb.localhost"
"domain": "smallweb.localhost",
"adminApps": [
"ls"
]
}
1 change: 1 addition & 0 deletions examples/cli/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
fetch: () => new Response("This app is supposed to be used from the cli: smallweb run cli"),
run() {
console.log("Hello, world!");
}
Expand Down
52 changes: 52 additions & 0 deletions examples/ls/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
async function handleRequest() {
const { SMALLWEB_DOMAIN, SMALLWEB_DIR } = Deno.env.toObject()
const entries = await Array.fromAsync(Deno.readDir(SMALLWEB_DIR))
const html = /* html */`
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
<table>
<thead>
<tr>
<th>Name</th>
<th>URL</th>
</tr>
</thead>
<tbody>
${entries.filter(entry => !entry.name.startsWith(".")).map(entry => `
<tr>
<td>${entry.name}</td>
<td><a href="https://${entry.name}.${SMALLWEB_DOMAIN}">https://${entry.name}.${SMALLWEB_DOMAIN}</a></td>
</tr>
`).join('')}
</tbody>
</table>
`
return new Response(html, {
headers: {
"content-type": "text/html"
}
})
}

export default {
fetch: handleRequest
}

0 comments on commit 5ab9bf4

Please sign in to comment.