+64
example/.github/copilot-instructions.md
+64
example/.github/copilot-instructions.md
···
104
104
}
105
105
```
106
106
107
+
### 4. Cron tasks
108
+
109
+
CLI commands can be scheduled to run at specific intervals using cron syntax. To enable it, create a `smallweb.json` file in the root of your app directory with the following structure:
110
+
111
+
```json
112
+
{
113
+
"crons": [{
114
+
// The schedule in cron syntax
115
+
"schedule": "*/5 * * * *",
116
+
// args to pass to the run function
117
+
"args": []
118
+
}]
119
+
}
120
+
```
121
+
107
122
## Common Tasks
108
123
109
124
Smallweb apps only have write access to the `data/` directory. You can use this directory to store state.
···
142
157
}
143
158
144
159
db.close();
160
+
```
161
+
162
+
## Private Apps
163
+
164
+
Apps can be protected behind authentication. To do this, you'll first need to make sure than an oidc provider is configured in the `.smallweb/config.json[c]` file.
165
+
166
+
```json
167
+
{
168
+
"oidc": {
169
+
// use lastlogin.net as the oidc provider if none is specified
170
+
"issuer": "https://lastlogin.net"
171
+
},
172
+
"authorizedEmails": [
173
+
"pomdtr@example.com"
174
+
]
175
+
}
176
+
```
177
+
178
+
Then, you can set the `private` property in the `smallweb.json` file to `true`:
179
+
180
+
```json
181
+
{
182
+
"private": true
183
+
}
184
+
```
185
+
186
+
Or protect only specific routes:
187
+
188
+
```json
189
+
{
190
+
"privateRoutes": [
191
+
"/admin/*"
192
+
]
193
+
}
194
+
```
195
+
196
+
The user email can then be retrieved using the `Remote-Email` header:
197
+
198
+
```ts
199
+
export default {
200
+
fetch(req: Request) {
201
+
const email = req.headers.get("Remote-Email");
202
+
if (!email) {
203
+
return new Response("Unauthorized", { status: 401 });
204
+
}
205
+
206
+
return new Response(`Hello ${email}`);
207
+
},
208
+
}
145
209
```
146
210
147
211
## Dependencies