Skip to content

Commit 39f6de9

Browse files
committed
added server example.
1 parent 2cff1fc commit 39f6de9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

server.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict'
2+
3+
const http = require('http')
4+
5+
const stringify = require('.')({
6+
type: 'object',
7+
properties: {
8+
hello: {
9+
type: 'string'
10+
},
11+
data: {
12+
type: 'number'
13+
},
14+
nested: {
15+
type: 'object',
16+
properties: {
17+
more: {
18+
type: 'string'
19+
}
20+
}
21+
}
22+
}
23+
})
24+
25+
const server = http.createServer(handle)
26+
27+
function handle (req, res) {
28+
const data = {
29+
hello: 'world',
30+
data: 42,
31+
nested: {
32+
more: 'data'
33+
}
34+
}
35+
if (req.url === '/JSON') {
36+
res.end(JSON.stringify(data))
37+
} else {
38+
res.end(stringify(data))
39+
}
40+
}
41+
42+
server.listen(3000)

0 commit comments

Comments
 (0)