-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsample.js
More file actions
220 lines (206 loc) · 6.24 KB
/
Copy pathsample.js
File metadata and controls
220 lines (206 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
var api = { console: { autoLoad: false} };
var express = require('express');
var router = api.router = express.Router();
var docRouter = require('docrouter').docRouter;
module.exports = api;
docRouter(router, '/api/sample', function (router) {
router.get('/json/:tparam1/:tparam2', function (req, res) {
var tparam1 = req.params.tparam1;
var tparam2 = req.params.tparam2;
var qparam = req.query['qparam'];
var o = { tparam1: tparam1, tparam2: tparam2, qparam: qparam };
console.log('o', o);
console.warn('o', o);
console.info('o', o);
console.error('o', o);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(o));
},
{
id: 'sample_json',
name: 'json',
usage: 'json tparam1 qparam [tparam2]',
example: 'json tparam1 qparamValue',
doc: 'sample for a GET command getting template params and a query param',
params: {
"tparam1": {
"short": "b",
"type": "string",
"doc": "template param",
"style": "template",
"required": "true"
},
"qparam": {
"short": "q",
"type": "string",
"doc": "querty string param",
"style": "query",
"required": "true"
},
tparam2: {
"short": "a",
"type": "string",
"doc": "template param",
"style": "template",
"required": "true",
"defaultValue": "someTemplateValue"
}
}
});
router.post('/html', function (req, res) {
var flag = req.query.flag;
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end("<div style='background-color: red;'>HTML output: body param: " + req.body.bparam +
" Flag: " + flag + "</div>");
},
{
id: 'sample_html',
name: 'html',
usage: 'html tparam qparam',
example: 'html tparam qparam',
doc: 'sample for a POST command getting a template param returning html',
params: {
"bparam": {
"short": "b",
"type": "string",
"doc": "post body param",
"style": "body",
"required": "true"
},
"flag": {
"short": "f",
"type": "bool",
"doc": "some boolean flag",
"style": "query",
"required": "true"
}
}
});
router.post('/htmlbcast', function (req, res) {
var flag = req.query.flag;
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end("<div class='anode-sample-class'>HTML output: (): POST Param: " + req.body.bparam +
" Flag: " + flag + "</div>");
},
{
id: 'sample_htmlbcast',
name: 'htmlbcast',
usage: 'htmlbcast tparam qparam',
example: 'htmlbcast tparam qparam',
doc: 'sample for a broadcasting POST command getting a template param returning html',
broadcast: true,
params: {
"bparam": {
"short": "b",
"type": "string",
"doc": "POST param",
"style": "body",
"required": "true"
},
"flag": {
"short": "f",
"type": "bool",
"doc": "some boolean flag",
"style": "query",
"required": "true"
}
},
controller: {
css: '.anode-sample-class{ background-color: green; }'
}
});
router.post('/htmlbcasthandler', function (req, res) {
var flag = req.query.flag;
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end("<div style='background-color: yellow;'>HTML output: (): POST Param: " + req.body.bparam +
" Flag: " + flag + "</div>");
},
{
id: 'sample_htmlbcasthandler',
name: 'htmlbcasthandler',
usage: 'htmlbcasthandler tparam qparam',
example: 'htmlbcasthandler tparam qparam',
doc: 'sample for a broadcasting POST command getting a template param returning html with handler',
broadcast: true,
params: {
"bparam": {
"short": "b",
"type": "string",
"doc": "POST param",
"style": "body",
"required": "true"
},
"flag": {
"short": "f",
"type": "bool",
"doc": "some boolean flag",
"style": "query",
"required": "true"
}
},
controller: {
url: '../../plugins/sample/sample2.js' // relative to /api/sample
}
});
router.get('/bcast', function (req, res) {
res.json({ host: process.env.COMPUTERNAME || 'local', someData: 'data' });
},
{
id: 'sample_bcast',
name: 'bcast',
usage: 'sample bcast',
example: 'sample bcast',
doc: 'sample for a broadcasting command',
broadcast: true
});
router.get('/handler/:tparam', function (req, res) {
var tparam = req.params.tparam;
var qparam = req.query['qparam'];
var o = { tparam: tparam };
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(o));
},
{
id: 'sample_handler',
name: 'handler',
usage: 'handler',
example: 'handler',
doc: 'sample for a GET command using external handler',
params: {
"tparam": {
"short": "t",
"type": "string",
"doc": "template param",
"style": "template",
"required": "true"
}
},
controller: {
url: '../../plugins/sample/sample.js', // relative to /api/sample
cssUrl: '../../plugins/sample/sample.css' // relative to /api/sample
}
});
router.get('/clientonly', function (req, res) {
res.writeHead(500);
res.end('we should not get here since this is only a client side command');
},
{
id: 'sample_clientonly',
name: 'clientonly',
usage: 'clientonly',
example: 'clientonly',
doc: 'sample for a client side only command',
params: {
"someparam": {
"short": "s",
"type": "string",
"doc": "some param",
"required": "true"
}
},
controller: {
clientOnly: true,
url: '../../plugins/sample/sample.js' // relative to /api/sample
}
});
});