1
Fork 0

typescript(translucid): i think i fixed it

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-01-22 22:14:51 +02:00 committed by prescientmoon
parent 220c6667a3
commit 6349cd4442
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
2 changed files with 12 additions and 10 deletions

View file

@ -30,7 +30,7 @@ class Translucid {
// console.log(`Binded room with name ${i} and path ${object[i].file} with classes ${classes}`)
}
}
bind(path = "/", filepath = "", classes = []) {
bind(path = "/", filepath = "", classes = [], sendFiles = false) {
this.app.get(path, async (req, res) => {
const readResults = await read_1.read(filepath);
const toRun = [];
@ -47,11 +47,12 @@ class Translucid {
});
}
decorated.push((prev) => {
// console.log(`${__dirname}/../../${filepath}`);
res.contentType(`${__dirname}/../../${filepath}`);
res.send(prev);
if (!sendFiles)
res.send(prev);
else
res.sendFile(prev);
});
decorated[0](readResults);
decorated[0](sendfiles ? readResults : `${__dirname}/../../${filepath}`);
});
}
}

View file

@ -35,7 +35,7 @@ class Translucid {
// console.log(`Binded room with name ${i} and path ${object[i].file} with classes ${classes}`)
}
}
bind(path:string = "/", filepath:string = "", classes:Array<string> = []):void{
bind(path:string = "/", filepath:string = "", classes:Array<string> = [],sendFiles:boolean=false):void{
this.app.get(path, async (req, res)=> {
const readResults = await read(filepath);
const toRun:Array<Function> = [];
@ -55,12 +55,13 @@ class Translucid {
});
}
decorated.push((prev:any):void => {
// console.log(`${__dirname}/../../${filepath}`);
res.contentType(`${__dirname}/../../${filepath}`);
res.send(prev);
if (!sendFiles)
res.send(prev);
else
res.sendFile(prev);
});
decorated[0](readResults);
decorated[0](sendfiles?readResults:`${__dirname}/../../${filepath}`);
});
}
}