UNPKG

1.97 kBMarkdownView Raw
1# Gaia Mock Server
2
3A [node.js][nodejs] mock server for the [Gaia][gaia] REST service.
4
5This mockserver can act as a simple replacement for the [Gaia][gaia] REST
6service in tests and as a standalone server. This mock server serve static
7files stored in the projects `data` directory.
8
9
10
11## Run as a standalone server
12
13Check out this repo, in the repo run the following:
14
15```bash
16$ npm install
17$ npm start
18```
19
20The mock server will then be running on: http://localhost:9050/.
21
22
23
24## Use as a library
25
26This mock server can be included in your own code and started by your own code.
27You can then controll and listen on what this application does within your own
28program.
29
30
31### Installation
32
33```bash
34$ npm install gaia-mock
35```
36
37### Constructor
38
39This constructs a new mock server:
40
41```js
42var server = new GaiaMockServer();
43```
44
45
46### Events
47
48The server emit the following events:
49
50 * `listen` - When the server is up running and listening for upcomming requests.
51 The first parameter to the `callback` is the port number its listening on.
52 * `close` - When the server has closed down.
53 * `request` - When the server receives a request. The first parameter to the
54 `callback` is the URL which was requested.
55
56
57### API
58
59The server has the following methods:
60
61
62#### .listen(port)
63
64Starts the server. `port` is the port number the server should listen on. If no
65value is given for `port` the server will attach itself to a available port.
66
67
68#### .close()
69
70Closes down the server.
71
72
73### Example
74
75```js
76var MockServer = require('gaia-mock');
77
78var gaia = new MockServer();
79
80gaia.on('listen', function (port) {
81 console.log('server is running on port: ' + port);
82});
83
84gaia.on('close', function (port) {
85 console.log('server stopped');
86});
87
88gaia.on('request', function (url) {
89 console.log('server got a request on: ' + url);
90});
91
92gaia.listen(8080);
93
94// gaia.close();
95```
96
97
98
99[nodejs]: http://http://nodejs.org/ "node.js"
100[gaia]: https://github.com/amedia/gaia "Gaia"