instaserve 0.1.15 → 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 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
- console.log(e)
39
- s.writeHead(404).end()
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instaserve",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Instant web stack",
5
5
  "main": "module.mjs",
6
6
  "bin": "./server.mjs",
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/server.mjs CHANGED
@@ -1,20 +1,20 @@
1
- #!/usr/bin/env node
2
-
3
- import server from './module.mjs'
4
- import { pathToFileURL } from 'node:url'
5
- import { resolve } from 'node:path'
6
- import fs from 'node:fs'
7
- const routesfile = resolve(process.env.routes || 'routes.mjs')
8
- const [npx, instaserve, cmd] = process.argv
9
-
10
- if (cmd === 'create' && !fs.existsSync(routesfile)) {
11
- fs.writeFileSync(routesfile, `export default {
12
- _debug: ({method, url}, s) => !console.log(method, url),
13
- _example: (r, s) => console.log('returning a falsy value (above) will stop the chain'),
14
- api: (r, s) => 'an example api response'
15
- }`)
16
- }
17
-
18
- const routesurl = pathToFileURL(routesfile).href
19
- const routes = (await import(routesurl)).default
1
+ #!/usr/local/bin/node
2
+
3
+ import server from './module.mjs'
4
+ import { pathToFileURL } from 'node:url'
5
+ import { resolve } from 'node:path'
6
+ import fs from 'node:fs'
7
+ const routesfile = resolve(process.env.routes || 'routes.mjs')
8
+ const [npx, instaserve, cmd] = process.argv
9
+
10
+ if (cmd === 'create' && !fs.existsSync(routesfile)) {
11
+ fs.writeFileSync(routesfile, `export default {
12
+ _debug: ({method, url}, s) => !console.log(method, url),
13
+ _example: (r, s) => console.log('returning a falsy value (above) will stop the chain'),
14
+ api: (r, s) => 'an example api response'
15
+ }`)
16
+ }
17
+
18
+ const routesurl = pathToFileURL(routesfile).href
19
+ const routes = (await import(routesurl)).default
20
20
  server(routes, process.env.port)
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')