1
Fork 0

typescript(translucid): deleted ts files

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-01-19 22:58:24 +02:00 committed by prescientmoon
parent 4c45df126c
commit 196b6ba241
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
4 changed files with 0 additions and 101 deletions

View file

@ -1,26 +0,0 @@
const express = require('express');
const http = require('http');
import {Translucid} from "./Translucid";
interface Server{
app:any,
server:any,
connect:Promise<any>
}
function QuickServer(port:number):any{
const app = express();
const server = http.Server(app);
const translucid = new Translucid(app);
return {
express,app,http,server,translucid,
connect:new Promise((resolve,reject) => {
server.listen(port,() => {
resolve("Connected");
});
})
}
}
export {QuickServer};

View file

@ -1,58 +0,0 @@
import {read} from "./read";
interface Midleware{
name:string;
run:Function;
keys:Array<string>;
}
function containsAny(array:Array<string>,keys:Array<string>):boolean{
for (let i = 0;i < keys.length;i++){
if (array.indexOf(keys[i]) != -1) return true;
}
return false;
}
class Translucid{
midleware:Array<Midleware> = [];
constructor(public app){
}
use(obj:Midleware):void{
this.midleware.push(obj);
}
bind(path:string="/",filepath:string="",
text:boolean=false,classes:Array<string>=[]):void{
this.app.get(path,async (req,res) => {
if (!text){
res.sendFile(`${__dirname}/${filepath}`);
}
else{
const readResults = await read(filepath);
const toRun = [];
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) => {
res.send(prev + "<br/>Sent from the last iteration");
});
decorated[0](readResults);
}
});
}
}
export {Translucid};

View file

@ -1,5 +0,0 @@
import {read} from "./read";
import {Translucid} from "./Translucid.js";
import {QuickServer} from "./QuickServer.js"
export {read,Translucid,QuickServer};

View file

@ -1,12 +0,0 @@
import {QuickServer,Translucid} from "./app";
const {app,translucid} = QuickServer(8000);
translucid.bind("/","index.html");
translucid.bind("/test","read.js",true,["class"]);
translucid.use({
name:"wow, a midleware",
run:(prev,req,res,next) => {
next("sent by a midleware");
},
keys:["class"]
});