[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[nodeJS] 200 Creating a server

"200-1 Creating a server with #createServer"
| httpServer |	
httpServer := NodeJS http createServer.
httpServer isNil ifTrue: [
    ^self error: '200-1 server should not be nil'
].
httpServer on: #listening do:[       
      self print: 'OK-> 200-1 Succesfull creating http server on port 8081'.
      
]. 
httpServer listen: 8081 hostname: '127.0.0.1'.


"200-2 Creating a server with #createServer:"
| httpServer |	
httpServer := NodeJS http createServer:[:req :resp| | request response |
   request := NodeIncomingMessage @ req.
   response := NodeHTTPServerResponse @ resp.
   response writeHead: 200.
   response end: 'Test 200-2'.
].
httpServer isNil ifTrue: [
    ^self error: '200-2 server should not be nil'
].
httpServer on: #listening do:[       
      self print: 'OK-> 200-2 Succesfull creating http server on port 8082'.
      httpServer close
]. 
httpServer listen: 8082 hostname: '127.0.0.1'.


Uploaded Image: alert.gifShould we close the server if test succeeded?