isite 2026.4.4 → 2026.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +72 -0
- package/README.md +5 -0
- package/apps/client-side/site_files/js/angular.min.js +1 -1
- package/desktop.ini +2 -0
- package/docs/agent-guide.md +51 -0
- package/docs/ai-context.md +130 -0
- package/docs/api-map.json +288 -0
- package/docs/examples-for-ai.md +186 -0
- package/docs/index.html +1009 -0
- package/docs/llms.txt +39 -0
- package/docs/script.js +86 -0
- package/docs/style.css +445 -0
- package/isite_files/js/angular.js +1 -1
- package/lib/eval.js +50 -44
- package/llms.txt +40 -0
- package/package.json +1 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# isite Examples For AI Agents
|
|
2
|
+
|
|
3
|
+
Use these recipes when generating code for this library.
|
|
4
|
+
|
|
5
|
+
## Minimal Server
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
var isite = require('isite');
|
|
9
|
+
var site = isite({ port: 8080 });
|
|
10
|
+
|
|
11
|
+
site.run();
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Static HTML Route
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
site.onGET({
|
|
18
|
+
name: '/',
|
|
19
|
+
path: site.dir + '/html/index.html',
|
|
20
|
+
parser: 'html',
|
|
21
|
+
compress: true,
|
|
22
|
+
cache: true
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## JSON API Route
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
site.onGET('/api/status', function (req, res) {
|
|
30
|
+
res.json({
|
|
31
|
+
done: true,
|
|
32
|
+
time: site.getDateTime()
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Dynamic Route Parameters
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
site.onGET('/post/:id/category/:cat_id', function (req, res) {
|
|
41
|
+
res.json({
|
|
42
|
+
id: req.params.id,
|
|
43
|
+
category: req.params.cat_id,
|
|
44
|
+
rawId: req.paramsRaw.id
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Read And Render A Site File
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
site.onGET('/profile', function (req, res) {
|
|
53
|
+
res.render('profile.html', {
|
|
54
|
+
user: req.session.user
|
|
55
|
+
}, {
|
|
56
|
+
parser: 'html',
|
|
57
|
+
compress: true
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Collection CRUD
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
var employees = site.connectCollection('employees');
|
|
66
|
+
|
|
67
|
+
site.onPOST('/api/employees/add', function (req, res) {
|
|
68
|
+
employees.insertOne(req.body, function (err, doc) {
|
|
69
|
+
res.json({ done: !err, error: err, doc: doc });
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
site.onPOST('/api/employees/all', function (req, res) {
|
|
74
|
+
employees.findMany({
|
|
75
|
+
where: req.body.where || {},
|
|
76
|
+
select: req.body.select || {},
|
|
77
|
+
sort: { id: -1 },
|
|
78
|
+
limit: 50
|
|
79
|
+
}, function (err, docs, count) {
|
|
80
|
+
res.json({ done: !err, error: err, list: docs, count: count });
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Update By ID
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
site.onPOST('/api/employees/update', function (req, res) {
|
|
89
|
+
employees.updateOne({
|
|
90
|
+
where: { id: req.body.id },
|
|
91
|
+
set: req.body
|
|
92
|
+
}, function (err, result) {
|
|
93
|
+
res.json({ done: !err, error: err, result: result });
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Delete By ID
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
site.onPOST('/api/employees/delete', function (req, res) {
|
|
102
|
+
employees.deleteOne({
|
|
103
|
+
where: { id: req.body.id }
|
|
104
|
+
}, function (err, result) {
|
|
105
|
+
res.json({ done: !err, error: err, result: result });
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Upload File
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
site.onPOST('/uploadFile', function (req, res) {
|
|
114
|
+
var response = { done: true };
|
|
115
|
+
var file = req.files.fileToUpload;
|
|
116
|
+
var newPath = site.options.upload_dir + '/' + file.originalFilename;
|
|
117
|
+
|
|
118
|
+
site.mv(file.filepath, newPath, function (err) {
|
|
119
|
+
if (err) {
|
|
120
|
+
response.done = false;
|
|
121
|
+
response.error = err;
|
|
122
|
+
}
|
|
123
|
+
res.json(response);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Download File
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
site.onGET('/files/report.pdf', function (req, res) {
|
|
132
|
+
res.download(site.options.download_dir + '/report.pdf', 'report.pdf');
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## WebSocket Route
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
site.onWS('/chat', function (client) {
|
|
140
|
+
client.onMessage = function (message) {
|
|
141
|
+
if (message.type === 'connected') {
|
|
142
|
+
client.send({ type: 'ready' });
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Custom App
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
// apps/tasks/app.js
|
|
152
|
+
module.exports = function (site) {
|
|
153
|
+
var tasks = site.connectCollection('tasks');
|
|
154
|
+
|
|
155
|
+
site.onGET('/tasks', function (req, res) {
|
|
156
|
+
res.render('tasks.html', {}, { parser: 'html' });
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
site.onPOST('/api/tasks/all', function (req, res) {
|
|
160
|
+
tasks.findMany({ where: {} }, function (err, docs, count) {
|
|
161
|
+
res.json({ done: !err, list: docs, count: count });
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Events
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
site.on('task created', function (task) {
|
|
171
|
+
site.log('Task created: ' + task.title);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
site.call('task created', { title: 'Write docs' });
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Server-Side HTML Tags
|
|
178
|
+
|
|
179
|
+
```html
|
|
180
|
+
<div x-import="navbar.html"></div>
|
|
181
|
+
<h1>##var.siteName##</h1>
|
|
182
|
+
<label>##word.user_name##</label>
|
|
183
|
+
<div x-permission="admin">Admin content</div>
|
|
184
|
+
<div x-feature="login">Logged in content</div>
|
|
185
|
+
```
|
|
186
|
+
|