Skip to content

Amanej/Direction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Direction

Build Status

A node based router - in progress

Demo

Usage

  • Define routes
    DirectionRoutes = [
        {
            name: "god-dag",
            method: "GET",
            handler: (req,res) => {
                let message = JSON.stringify({"message":"Hei, ha en god dag!"});
                res.end(message);
            }
        },
        {
            name: "bootstrap",
            method: "GET",
            handler: (req,res) => {
                let file = fs.readFileSync("./test/helpers/bootstrap.html","utf-8");
                res.end(file);
            }
        }
    ]

Routes are expected to be:

    name - Route - String
    method - HTTP Method - String
    handler - Response function - Function
  • Init Router
    const DirectionRouter = new Direction(DirectionRoutes);
  • Pass to server
    const server = http.createServer((req,res) => {
        DirectionRouter.handleRequests(req,res)
    });    

Features

  • Basic json routes
  • Serve HTML

Todo

  • Serve HTML
  • Request flow works with external data sources
  • Serve static file
  • Serve static files folder
  • Process post request
  • Let user define route by name and method
  • Handle file uploads
  • Pass headers to route function
  • Handle parameters well

Battle test

  • Build basic homepage with router
  • Build webapp with router

About

NodeJS based router

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages