-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment2.json
239 lines (239 loc) · 7.01 KB
/
assignment2.json
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
[
{
"id": "196c35a1.639ada",
"type": "tab",
"label": "Flow 4"
},
{
"id": "28ae01f6.44760e",
"type": "http in",
"z": "196c35a1.639ada",
"name": "/time",
"url": "/time",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 120,
"y": 100,
"wires": [
[
"4a6279b3.70d388"
]
]
},
{
"id": "95698120.475f2",
"type": "http response",
"z": "196c35a1.639ada",
"name": "HTTP Response",
"x": 1000.0000152587891,
"y": 188.7500057220459,
"wires": []
},
{
"id": "a502fc69.196a7",
"type": "function",
"z": "196c35a1.639ada",
"name": "Setting HTTP Headers",
"func": "msg.headers = {\"content-type\" : \"application/json\"};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 770.2500114440918,
"y": 189.0000057220459,
"wires": [
[
"95698120.475f2"
]
]
},
{
"id": "4a6279b3.70d388",
"type": "function",
"z": "196c35a1.639ada",
"name": "curr timestamp",
"func": "var now = new Date();\n\nvar hours = now.getHours();\nvar minutes = now.getMinutes();\n\nif ( hours < 10 )\n{\n hours = \"0\" + hours;\n}\n\nif ( minutes < 10 )\n{\n minutes = \"0\" + minutes\n}\n\nmsg.payload = hours+\":\"+minutes;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 288,
"y": 146,
"wires": [
[
"a40b560d.ca4438",
"837764fe.f86548"
]
]
},
{
"id": "a40b560d.ca4438",
"type": "template",
"z": "196c35a1.639ada",
"name": "JSON template",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{\"time\" : \"{{payload}}\"}",
"x": 508.50000762939453,
"y": 145.75000476837158,
"wires": [
[
"a502fc69.196a7"
]
]
},
{
"id": "7480664e.24fb38",
"type": "http in",
"z": "196c35a1.639ada",
"name": "/random",
"url": "/random",
"method": "get",
"swaggerDoc": "",
"x": 97,
"y": 211,
"wires": [
[
"bc333e5b.619d9"
]
]
},
{
"id": "bc333e5b.619d9",
"type": "random",
"z": "196c35a1.639ada",
"name": "",
"low": "1",
"high": "10",
"inte": "true",
"x": 253,
"y": 257,
"wires": [
[
"daf6c2df.ed2ef",
"b5b4cfb8.560dd",
"3dc78681.50b43a"
]
]
},
{
"id": "daf6c2df.ed2ef",
"type": "template",
"z": "196c35a1.639ada",
"name": "JSON template",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{\"random\" : {{payload}} }",
"x": 511.00000762939453,
"y": 258.2500057220459,
"wires": [
[
"a502fc69.196a7"
]
]
},
{
"id": "b27bcaa8.c9ddf8",
"type": "http in",
"z": "196c35a1.639ada",
"name": "/page",
"url": "/page",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 97,
"y": 515.2500076293945,
"wires": [
[
"76dbb7c2.e7c628"
]
]
},
{
"id": "b5b4cfb8.560dd",
"type": "function",
"z": "196c35a1.639ada",
"name": "Caching random num",
"func": "flow.set('lastRandomNum', msg.payload);",
"outputs": "0",
"noerr": 0,
"x": 524.7500076293945,
"y": 333.25000762939453,
"wires": []
},
{
"id": "837764fe.f86548",
"type": "function",
"z": "196c35a1.639ada",
"name": "Caching timestamp",
"func": "flow.set('lastServerTime', msg.payload);",
"outputs": "0",
"noerr": 0,
"x": 518.1250076293945,
"y": 74.00000381469727,
"wires": []
},
{
"id": "f2f54e4b.c50d4",
"type": "template",
"z": "196c35a1.639ada",
"name": "Generate HTML",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{{#lastServerTime}}\nTime last server time request received at {{lastServerTime}}\n{{/lastServerTime}}\n\n{{^lastServerTime}}\nNo server time requests have been received\n{{/lastServerTime}}\n\n<br/>\n{{#lastRandomNum}}\nLast random number request returned {{lastRandomNum}}, which was received at {{lastRandomNumTimestamp}}\n{{/lastRandomNum}}\n\n{{^lastRandomNum}}\nNo requests for random numbers have been received\n{{/lastRandomNum}}",
"x": 541.8750076293945,
"y": 514.0000076293945,
"wires": [
[
"95698120.475f2"
]
]
},
{
"id": "76dbb7c2.e7c628",
"type": "function",
"z": "196c35a1.639ada",
"name": "Get cached values",
"func": "// Get cached timestamp and random num\n\nvar lastServerTime = flow.get('lastServerTime');\nvar lastRandomNum = flow.get('lastRandomNum');\nvar lastRandomNumTimestamp = flow.get('lastRandomNumTimestamp');\n\nmsg.lastServerTime = lastServerTime;\nmsg.lastRandomNum = lastRandomNum;\nmsg.lastRandomNumTimestamp = lastRandomNumTimestamp;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 303.12500762939453,
"y": 515.2500076293945,
"wires": [
[
"f2f54e4b.c50d4"
]
]
},
{
"id": "3dc78681.50b43a",
"type": "function",
"z": "196c35a1.639ada",
"name": "curr timestamp",
"func": "var now = new Date();\n\nvar hours = now.getHours();\nvar minutes = now.getMinutes();\n\nif ( hours < 10 )\n{\n hours = \"0\" + hours;\n}\n\nif ( minutes < 10 )\n{\n minutes = \"0\" + minutes\n}\n\nmsg.payload = hours+\":\"+minutes;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 278.12500762939453,
"y": 390.25000762939453,
"wires": [
[
"bb071811.07c468"
]
]
},
{
"id": "bb071811.07c468",
"type": "function",
"z": "196c35a1.639ada",
"name": "Caching random num timestamp",
"func": "flow.set('lastRandomNumTimestamp', msg.payload);\nreturn msg;",
"outputs": "0",
"noerr": 0,
"x": 584.375,
"y": 390.25,
"wires": []
}
]