typescript(translucid): updated docs
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
8d274609bb
commit
56a27a0398
|
@ -22,12 +22,6 @@ The ".QuickServer" method return many useful objects:
|
||||||
```
|
```
|
||||||
const {app,server,connect,translucid} = trans.QuickServer(8000);
|
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:
|
The translucid object can be used to make file bindings:
|
||||||
```
|
```
|
||||||
translucid.bind("/","client/index.html",["myId"]);
|
translucid.bind("/","client/index.html",["myId"]);
|
||||||
|
@ -38,9 +32,43 @@ translucid.use({
|
||||||
name:"my middleware",
|
name:"my middleware",
|
||||||
keys:["myid"],
|
keys:["myid"],
|
||||||
run:(prev,req,res,next) => {
|
run:(prev,req,res,next) => {
|
||||||
//prev is the data that is going to be sent to the client
|
next(`${prev} <br/> string added by a middleware`);//passing the argument is optional
|
||||||
//(it might for example be the index.html file);
|
|
||||||
next(`${prev} <br/> string added by a middleware`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Translucid {
|
||||||
const decorated = [];
|
const decorated = [];
|
||||||
const expressArgs = [req, res];
|
const expressArgs = [req, res];
|
||||||
for (let i = 0; i < toRun.length; i++) {
|
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]);
|
toRun[i](prev, ...expressArgs, decorated[i + 1]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Translucid {
|
||||||
const expressArgs = [req, res];
|
const expressArgs = [req, res];
|
||||||
|
|
||||||
for (let i = 0; i < toRun.length; i++) {
|
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]);
|
toRun[i](prev, ...expressArgs, decorated[i + 1]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue