1
Fork 0
solar-conflux/typescript/translucid
Matei Adriel 56a27a0398
typescript(translucid): updated docs
Signed-off-by: prescientmoon <git@moonythm.dev>
2019-01-28 20:01:16 +02:00
..
.gitignore typescript(translucid): testing automated update 2019-01-22 21:11:05 +02:00
app.js typescript(translucid): first commit 2019-01-19 22:41:54 +02:00
LICENSE typescript(translucid): Initial commit 2019-01-19 20:41:18 +02:00
package-lock.json typescript(translucid): 1.0.31 2019-01-22 22:35:53 +02:00
package.json typescript(translucid): 1.0.31 2019-01-22 22:35:53 +02:00
QuickServer.js typescript(translucid): unknown bug 2019-01-22 20:45:32 +02:00
read.js typescript(translucid): idk anymore 2019-01-20 12:45:23 +02:00
README.md typescript(translucid): updated docs 2019-01-28 20:01:16 +02:00
test.js typescript(translucid): fixed the bug 2019-01-22 20:49:50 +02:00
test.ts typescript(translucid): fixed the bug 2019-01-22 20:49:50 +02:00
Translucid.js typescript(translucid): updated docs 2019-01-28 20:01:16 +02:00
Translucid.ts typescript(translucid): updated docs 2019-01-28 20:01:16 +02:00
tsconfig.json typescript(translucid): typescipited 2019-01-22 20:26:18 +02:00

Translucid

A simple node.js library to bind files to requests

Get started:

First you need to install the package:

npm install translucid --save

Then, you need to include it in your project:

const trans = require("translucid");

To create your first server, call ".QuickServer(port)":

trans.QuickServer(8000);

The ".QuickServer" method return many useful objects:

const {app,server,connect,translucid} = trans.QuickServer(8000);

The translucid object can be used to make file bindings:

translucid.bind("/","client/index.html",["myId"]);

Then you can add middleware like this:

translucid.use({
    name:"my middleware",
    keys:["myid"],
    run:(prev,req,res,next) => {
        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