1
Fork 0

typescript(translucid): deprecations

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-01-20 12:57:11 +02:00 committed by prescientmoon
parent 39afed78dc
commit 62bf58898e
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
2 changed files with 16 additions and 21 deletions

View file

@ -30,7 +30,7 @@ connect.then(() => {
``` ```
The translucid object can be used to make file bindings: The translucid object can be used to make file bindings:
``` ```
translucid.bind("/","client/index.html",true,["myId"]); translucid.bind("/","client/index.html",["myId"]);
``` ```
Then you can add middleware like this: Then you can add middleware like this:
``` ```

View file

@ -16,31 +16,26 @@ class Translucid {
use(obj) { use(obj) {
this.midleware.push(obj); this.midleware.push(obj);
} }
bind(path = "/", filepath = "", text = false, classes = []) { bind(path = "/", filepath = "", classes = []) {
this.app.get(path, async (req, res) => { this.app.get(path, async (req, res) => {
if (!text) { const readResults = await read_1.read(filepath);
console.error("Blocking reading acces s deprecated, and would be remove in the next version."); const toRun = [];
for (let i of this.midleware) {
if (containsAny(classes, i.keys)) {
toRun.push(i.run);
}
} }
else { const decorated = [];
const readResults = await read_1.read(filepath); const expressArgs = [req, res];
const toRun = []; for (let i = 0; i < toRun.length; i++) {
for (let i of this.midleware) {
if (containsAny(classes, i.keys)) {
toRun.push(i.run);
}
}
const decorated = [];
const expressArgs = [req, res];
for (let i = 0; i < toRun.length; i++) {
decorated.push((prev) => {
toRun[i](prev, ...expressArgs, decorated[i + 1]);
});
}
decorated.push((prev) => { decorated.push((prev) => {
res.send(prev); toRun[i](prev, ...expressArgs, decorated[i + 1]);
}); });
decorated[0](readResults);
} }
decorated.push((prev) => {
res.send(prev);
});
decorated[0](readResults);
}); });
} }
} }