instaserve 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/module.mjs +3 -2
- package/package.json +1 -1
- package/routes.mjs +2 -1
- package/test.mjs +5 -1
package/module.mjs
CHANGED
|
@@ -35,8 +35,9 @@ export default function (routes, port = 3000) {
|
|
|
35
35
|
}
|
|
36
36
|
throw Error(r.url + ' not found')
|
|
37
37
|
} catch (e) {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const err = JSON.stringify({error: e.message})
|
|
39
|
+
console.log('Server error: ' + e)
|
|
40
|
+
s.writeHead(404).end(err)
|
|
40
41
|
}
|
|
41
42
|
})
|
|
42
43
|
}).listen(process.env.port || port)
|
package/package.json
CHANGED
package/routes.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
_debug: ({method, url}, s) => !console.log(method, url),
|
|
3
3
|
_example: (r, s) => console.log('returning a falsy value (above) will stop the chain'),
|
|
4
|
-
api: (r, s) => 'an example api response'
|
|
4
|
+
api: (r, s) => 'an example api response',
|
|
5
|
+
testerror: () => { throw new Error('this from testerror') }
|
|
5
6
|
}
|
package/test.mjs
CHANGED
|
@@ -26,7 +26,8 @@ const server2 = serve({
|
|
|
26
26
|
__: ({headers: {host}, method, url}) => console.log(host, method, url),
|
|
27
27
|
str: () => 'ok',
|
|
28
28
|
obj: x => ({a: 'ok'}),
|
|
29
|
-
undef: () => undefined
|
|
29
|
+
undef: () => undefined,
|
|
30
|
+
testerror: () => { throw new Error('this from testerror')}
|
|
30
31
|
}, 8085)
|
|
31
32
|
te(server2.port, 8085)
|
|
32
33
|
te(server2.routes.str(), 'ok')
|
|
@@ -40,5 +41,8 @@ te(return_obj.a, 'ok')
|
|
|
40
41
|
const return_undefined = await get('http://localhost:8085/undef')
|
|
41
42
|
te(return_undefined, '')
|
|
42
43
|
|
|
44
|
+
const test_error = await get('http://localhost:8085/testerror')
|
|
45
|
+
te(test_error.error, 'this from testerror')
|
|
46
|
+
|
|
43
47
|
server2.stop()
|
|
44
48
|
console.log('tests complete')
|