codehooks-js 1.2.18 → 1.2.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codehooks-js",
3
- "version": "1.2.18",
3
+ "version": "1.2.20",
4
4
  "type": "module",
5
5
  "description": "Codehooks.io official library - provides express.JS like syntax",
6
6
  "main": "index.js",
package/types/index.d.ts CHANGED
@@ -381,7 +381,7 @@ export type DatastoreAPI = {
381
381
  /**
382
382
  * - Set a key-value pair in the current Datastore
383
383
  */
384
- set: (key: string, value: string, options?: object) => Promise<any>;
384
+ set: (key: string, value: string | object, options?: object) => Promise<any>;
385
385
  /**
386
386
  * - Get a key-value pair in the current Datastore
387
387
  */
package/webserver.mjs CHANGED
@@ -35,7 +35,12 @@ export function serveStatic(options, app, filestore, hook, fsoptions) {
35
35
  }
36
36
  const type = mime.getType(filePath)
37
37
  if (!type) {
38
- next(`Static server: ${filePath} is not a valid file name`)
38
+ if (options.notFound) {
39
+ // continue to next middleware
40
+ next()
41
+ } else {
42
+ next(`Static server: ${filePath} is not a valid file name`)
43
+ }
39
44
  } else {
40
45
  // ok to grant public access to file
41
46
  next()
@@ -87,8 +92,27 @@ export function serveStatic(options, app, filestore, hook, fsoptions) {
87
92
 
88
93
  } catch (error) {
89
94
  console.debug("Error message", error.message)
90
- console.debug(error)
91
- res.status(404).end(`No file here: ${filePath} (${error.message})`)
95
+ if (options.notFound) {
96
+ // read default file
97
+ // add directory filesystem path
98
+ filePath = options.notFound;
99
+ if (options.directory && options.directory !== undefined && options.directory !== '/') {
100
+ filePath = options.directory + filePath;
101
+ }
102
+ console.debug('Read notFound file', filePath)
103
+ const type = mime.getType(filePath)
104
+ const filestream = await filestore.getReadStream(filePath, fsoptions);
105
+ res.set('Content-Type', type || 'application/octet-stream');
106
+ filestream
107
+ .on('data', (buf) => {
108
+ res.write(buf, 'buffer')
109
+ })
110
+ .on('end', () => {
111
+ res.end()
112
+ })
113
+ } else {
114
+ res.status(404).end(`No file here: ${filePath} (${error.message})`)
115
+ }
92
116
  }
93
117
  }
94
118
  const farr = [readFunc]