0.0.3 • Published 12 months ago

httptree v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

httptree 🌲

npm Web framework to make http and https modules easier to use

Feature

  • Referred to express, excellent web framework
  • Created for use in my some another project
  • Modularization of server Routing logic

Usage

//@ts-check
const httptree = require('../lib')
const http = require('http')

// creage httptree module
const hp = new httptree.Server() 
const port = 3000

// add get methon in '/' path
hp.get((req,res,data,obj)=>{ 
    console.log('res / ans',res.statusCode)
    res.send('<a href="#">hello httptree!!</a>')
})
hp.path('index.html').get((req,res,data,obj)=>{

    // Existing functions inside  http module can be used.
    res.setHeader('Access-Control-Allow-Origin','*')
    console.log('res index.html',res.statusCode, data)
    res.sendFile(__dirname+'\\index.html')
})

console.log('this structure:',hp.printStructure())
http.createServer((req,res)=>{ 
    console.log('req:',req.url)

    // hp.parse return boolean that Whether it sent a reply to the client
    return hp.parse(req,res,{}) ||

    // httptree.httpError is simple http error handler
    httptree.httpError(404,res,'not file')

}).listen(port,()=>console.log('server port:',port))
0.0.3

12 months ago

0.0.2

1 year ago

0.0.1

2 years ago

0.0.0

2 years ago