pico-engine 1.0.9 → 1.2.0
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/README.md +0 -1
- package/dist/RulesetRegistryLoaderFs.js +2 -2
- package/dist/cli.js +1 -1
- package/dist/index.js +9 -9
- package/dist/server.js +46 -6
- package/krl/io.picolabs.pico-engine-ui.krl +8 -7
- package/krl/io.picolabs.wrangler.krl +47 -16
- package/package.json +6 -6
- package/public/docs/krl/modules/ctx.md +5 -1
- package/public/pico-engine-ui.css +2 -2
- package/public/pico-engine-ui.js +6 -6
- package/src/RulesetRegistryLoaderFs.ts +1 -1
- package/src/server.ts +39 -2
package/src/server.ts
CHANGED
|
@@ -21,6 +21,16 @@ export function server(core: PicoEngineCore, uiECI: string): Express {
|
|
|
21
21
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
22
22
|
next();
|
|
23
23
|
});
|
|
24
|
+
app.use('*',(req,res,next) =>{
|
|
25
|
+
if (req.method == "OPTIONS") {
|
|
26
|
+
res.header("Allow", "POST, GET, OPTIONS");
|
|
27
|
+
res.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
|
|
28
|
+
res.status(200);
|
|
29
|
+
res.send();
|
|
30
|
+
}else{
|
|
31
|
+
next();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
24
34
|
app.use(helmet());
|
|
25
35
|
app.use(express.static(path.resolve(__dirname, "..", "public")));
|
|
26
36
|
app.use(
|
|
@@ -109,6 +119,24 @@ export function server(core: PicoEngineCore, uiECI: string): Express {
|
|
|
109
119
|
time: 0, // TODO remove this typescript requirement
|
|
110
120
|
})
|
|
111
121
|
.then((data) => {
|
|
122
|
+
if (data.directives) {
|
|
123
|
+
var _res = _.filter(data.directives, { name: "_cookie" });
|
|
124
|
+
if (_res) {
|
|
125
|
+
_.forEach(_res, function(v) {
|
|
126
|
+
if (v.options && v.options.cookie) {
|
|
127
|
+
res.append("Set-Cookie", v.options.cookie);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
var _res = _.filter(data.directives, { name: "_redirect" });
|
|
132
|
+
if (_res) {
|
|
133
|
+
_.forEach(_res, function(v) {
|
|
134
|
+
if (v.options && v.options.url) {
|
|
135
|
+
return res.redirect(v.options.url);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
112
140
|
res.json(data);
|
|
113
141
|
})
|
|
114
142
|
.catch(next);
|
|
@@ -142,15 +170,24 @@ export function server(core: PicoEngineCore, uiECI: string): Express {
|
|
|
142
170
|
);
|
|
143
171
|
|
|
144
172
|
app.all("/c/:eci/query/:rid/:name", function (req, res, next) {
|
|
173
|
+
const funcPart = req.params.name.split(".");
|
|
145
174
|
core
|
|
146
175
|
.query({
|
|
147
176
|
eci: req.params.eci,
|
|
148
177
|
rid: req.params.rid,
|
|
149
|
-
name:
|
|
178
|
+
name: funcPart[0],
|
|
150
179
|
args: mergeGetPost(req),
|
|
151
180
|
})
|
|
152
181
|
.then((data) => {
|
|
153
|
-
|
|
182
|
+
if (funcPart[1] === "html") {
|
|
183
|
+
res.header("Content-Type", "text/html");
|
|
184
|
+
res.end(data);
|
|
185
|
+
} else if (funcPart[1] === "txt") {
|
|
186
|
+
res.header("Content-Type", "text/plain");
|
|
187
|
+
res.end(data);
|
|
188
|
+
} else {
|
|
189
|
+
res.json(data);
|
|
190
|
+
}
|
|
154
191
|
})
|
|
155
192
|
.catch(next);
|
|
156
193
|
});
|