Last active
          October 25, 2018 16:43 
        
      - 
      
- 
        Save daniel12fsp/a9ad247313dec2e368eefed02a985191 to your computer and use it in GitHub Desktop. 
    Simple implementation of HTTP in Node
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const net = require('net'); | |
| const server = net.createServer(function (socket) { | |
| socket.on('data', function (data) { | |
| const header = data.toString(); | |
| console.log("--------start request--------"); | |
| console.log(header); | |
| console.log("--------end request--------"); | |
| let response = "HTTP/1.1 200 OK\r\n"; | |
| body = "<h1> HELLO WORLD 😉 </h1>"; | |
| response += 'Content-Length: ' + body.length + '\r\n'; | |
| response += 'Content-Type: text/html; charset=utf-8\r\n'; | |
| response += '\r\n'; | |
| response += body; | |
| socket.write(response); | |
| socket.pipe(socket); | |
| }) | |
| }); | |
| server.listen(8080, 'localhost'); | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment