UNPKG

583 Btext/coffeescriptView Raw
1http = require 'http'
2url = require 'url'
3events = require 'eventemitter2'
4
5module.exports = class TestServer extends events.EventEmitter2
6
7 constructor: ->
8 @app = http.createServer (req, res) =>
9 _url = url.parse(decodeURI(req.url), true)
10 if _url.pathname == '/'
11 res.writeHead 200
12 res.end 'linda test server'
13
14 @emit 'request', req
15
16 @io = require('socket.io').listen(@app)
17
18 @linda = require('../').Server.listen(io: @io, server: @app)
19
20 listen: (@port) ->
21 @app.listen(@port)
22 return @
23
24 close: ->
25 @app.close()
26 return @