Sha256: 53a1d12c60089f093ebb884327d986a4f65a7a31ad3f044e3882024ab8c8f619

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

Object subclass: #TrivialServer
        instanceVariableNames: 'counter'
        category: 'TrivialServer'!

!TrivialServer methodsFor: 'initializing'!
initialize
        counter := 0
! !

!TrivialServer methodsFor: 'processing'!
process: aRequest
        | hostname httpVersion stream |
	counter := counter + 1.

        "Calling a method in a js module"
	hostname := os hostname.

        "Accessing a property of js HTTP request object"
        httpVersion := aRequest httpVersion.

        stream := String new writeStream.
	stream
		nextPutAll: '<html><p>Request HTTP version: ', httpVersion, '</p>';
		nextPutAll: '<p>OS hostname: ', hostname, '</p>';
		nextPutAll: '<p>Number of requests: ', counter asString, '</p></html>'.
	^stream contents
!

start
        | block obj |
        block := [:req :res || headers |
	    headers := Dictionary with: 'content-type' -> 'text/html'.
	    res writeHead: (Array with: 200 with: headers).
	    res end: (self process: req)].

        (http createServer: block)
                listen: 1337 host: '127.0.0.1'.
        console log: 'TrivialServer running at http://127.0.0.1:1337/'
! !


!TrivialServer class methodsFor: 'initialization'!
initialize
        "We require these Node modules."
    os := require value: 'os'.
    http := require value: 'http'.
!

main
	self new start
! !

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
mdbe-0.1.0 public/amber/examples/nodejs/trivialserver/TrivialServer.st
maglev-database-explorer-0.0.5 public/amber/examples/nodejs/trivialserver/TrivialServer.st
maglev-database-explorer-0.0.4 public/amber/examples/nodejs/trivialserver/TrivialServer.st
maglev-database-explorer-0.0.3 public/amber/examples/nodejs/trivialserver/TrivialServer.st
maglev-database-explorer-0.0.2 public/amber/examples/nodejs/trivialserver/TrivialServer.st
maglev-database-explorer-0.0.1 public/amber/examples/nodejs/trivialserver/TrivialServer.st