Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var url=require('url');
- var fs=require('fs');
- function renderHTML(path,response){
- fs.readFile(path,null,function(error,data){
- if(error){
- response.writeHead(404);
- response.write('file not found');
- }else{
- response.write(data);
- }
- response.end();
- })
- }
- module.exports={
- handleRequest:function(request,response){
- response.writeHead(200,{'Content-type':'text/html'})
- var path=url.parse(request.url).pathname;
- switch(path){
- case '/':
- renderHTML('index.html',response)
- break;
- case '/login':
- renderHTML('login.html',response)
- break;
- default:
- response.writeHead(404);
- response.write('Route is not define');
- response.end();
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement