1
Fork 0

typescript(translucid): updated docs

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-01-28 20:01:16 +02:00 committed by prescientmoon
parent 8d274609bb
commit 56a27a0398
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
3 changed files with 39 additions and 11 deletions

View file

@ -22,12 +22,6 @@ The ".QuickServer" method return many useful objects:
```
const {app,server,connect,translucid} = trans.QuickServer(8000);
```
"Connect" is a promise that resolves when the server starts listening to the port:
```
connect.then(() => {
console.log("Listening on port 8000!");
});
```
The translucid object can be used to make file bindings:
```
translucid.bind("/","client/index.html",["myId"]);
@ -38,9 +32,43 @@ translucid.use({
name:"my middleware",
keys:["myid"],
run:(prev,req,res,next) => {
//prev is the data that is going to be sent to the client
//(it might for example be the index.html file);
next(`${prev} <br/> string added by a middleware`);
next(`${prev} <br/> string added by a middleware`);//passing the argument is optional
}
});
```
You can make a folder public like this:
```
translucid.public(`client`);
```
You can read bindings from a file:
```
translucid.bindJSON(`data/files.json`);
```
And in files.json:
```
{
"/articles":{
"file":"client/articles.html",
"classes":["*"]
},
"/":{
"file":"client/start.html",
"classes":["*"]
},
"/start":{
"file":"client/start.html",
"classes":["*"]
}
}
```
The QuickServer returns: * translucid => the basic translucid object
* express => the express module
* http => the http module
* server => instance of http.Server()
* connect => a promise that resolves when the server is listening to the specified port
Other utilities in translucid: * read => read a file

View file

@ -45,7 +45,7 @@ class Translucid {
const decorated = [];
const expressArgs = [req, res];
for (let i = 0; i < toRun.length; i++) {
decorated.push((prev) => {
decorated.push((prev = (!sendFiles) ? readResults : `${dir}/${filepath}`) => {
toRun[i](prev, ...expressArgs, decorated[i + 1]);
});
}

View file

@ -53,7 +53,7 @@ class Translucid {
const expressArgs = [req, res];
for (let i = 0; i < toRun.length; i++) {
decorated.push((prev:any):void => {
decorated.push((prev:any=(!sendFiles)?readResults:`${dir}/${filepath}`):void => {
toRun[i](prev, ...expressArgs, decorated[i + 1]);
});
}