A node based router - in progress
- 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)
});
- Basic json routes
- Serve HTML
Serve HTMLRequest flow works with external data sourcesServe 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
Build basic homepage with routerBuild webapp with router