1
0

TrivialServer.st 859 B

123456789101112131415161718192021222324252627282930313233
  1. Object subclass: #TrivialServer
  2. instanceVariableNames: 'counter'
  3. category: 'TrivialServer'!
  4. !TrivialServer methodsFor: 'initializing'!
  5. initialize
  6. counter := 0
  7. ! !
  8. !TrivialServer methodsFor: 'processing'!
  9. process: aRequest
  10. | hostname httpVersion stream |
  11. counter := counter + 1.
  12. "Calling a method in a js module"
  13. hostname := {'os.hostname()'}.
  14. "Accessing a property of js HTTP request object"
  15. httpVersion := {'aRequest.httpVersion'}.
  16. stream := String new writeStream.
  17. stream
  18. nextPutAll: '<html><p>Request HTTP version: ', httpVersion, '</p>';
  19. nextPutAll: '<p>OS hostname: ', hostname, '</p>';
  20. nextPutAll: '<p>Number of requests: ', counter asString, '</p></html>'.
  21. ^stream contents
  22. ! !
  23. !TrivialServer class methodsFor: 'initialization'!
  24. initialize
  25. {'os = require(''os'');'}
  26. ! !