@srfnstack/spliffy 1.2.2 → 1.2.4

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,9 +1,9 @@
1
1
  {
2
2
  "name": "@srfnstack/spliffy",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "author": "snowbldr",
5
5
  "private": false,
6
- "homepage": "https://github.com/narcolepticsnowman/spliffy",
6
+ "homepage": "https://github.com/SRFNStack/spliffy",
7
7
  "license": "MIT",
8
8
  "type": "module",
9
9
  "files": [
@@ -14,7 +14,7 @@
14
14
  "main": "src/index.mjs",
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git@github.com:narcolepticsnowman/spliffy.git"
17
+ "url": "git@github.com:SRFNStack/spliffy.git"
18
18
  },
19
19
  "scripts": {
20
20
  "test": "npm run lint:fix && jest",
package/src/handler.mjs CHANGED
@@ -185,7 +185,7 @@ const handleRequest = async (req, res, handler, middleware, errorTransformer) =>
185
185
  }
186
186
  }
187
187
 
188
- export const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE']
188
+ export const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE', 'WEBSOCKET']
189
189
 
190
190
  let currentDate = new Date().toISOString()
191
191
  setInterval(() => { currentDate = new Date().toISOString() }, 1000)
package/src/routes.mjs CHANGED
@@ -140,8 +140,10 @@ const buildJSHandlerRoute = async (name, filePath, urlPath, inheritedMiddleware,
140
140
  if (typeof loadedHandler.handler === 'function') {
141
141
  handler = loadedHandler.handler
142
142
  }
143
- if (typeof handler !== 'function') {
144
- throw new Error(`Request method ${method} in file ${filePath} must be a function. Got: ${handlers[method]}`)
143
+ if (typeof handler !== 'function' && method !== 'WEBSOCKET') {
144
+ throw new Error(`Request method ${method} in file ${filePath} must be a function. Got: ${typeof handlers[method]}`)
145
+ } else if(method === 'WEBSOCKET' && typeof handler !== 'object') {
146
+ throw new Error(`Websocket in file ${filePath} must be an object. Got: ${typeof handlers[method]}`)
145
147
  }
146
148
  if (!('streamRequestBody' in loadedHandler)) {
147
149
  handler.streamRequestBody = handlers.streamRequestBody
package/src/server.mjs CHANGED
@@ -19,18 +19,19 @@ const appMethods = {
19
19
  OPTIONS: 'options',
20
20
  HEAD: 'head',
21
21
  CONNECT: 'connect',
22
- TRACE: 'trace'
22
+ TRACE: 'trace',
23
+ WEBSOCKET: 'ws'
23
24
  }
24
25
  const optionsHandler = (config, middleware, methods) => {
25
- return createHandler(() => ({
26
- headers: {
27
- allow: methods
28
- },
29
- statusCode: 204
30
- }),
31
- middleware,
32
- [],
33
- config
26
+ return createHandler(() => ( {
27
+ headers: {
28
+ allow: methods
29
+ },
30
+ statusCode: 204
31
+ } ),
32
+ middleware,
33
+ [],
34
+ config
34
35
  )
35
36
  }
36
37
 
@@ -68,7 +69,7 @@ const getHttpsApp = (key, cert) => {
68
69
  export async function startServer (config) {
69
70
  if (!state.initialized) {
70
71
  state.initialized = true
71
- const routes = [...getNodeModuleRoutes(config), ...(await findRoutes(config))]
72
+ const routes = [...getNodeModuleRoutes(config), ...( await findRoutes(config) )]
72
73
  let app, port
73
74
  if (config.httpsKeyFile) {
74
75
  app = getHttpsApp(config.secure)
@@ -97,7 +98,12 @@ export async function startServer (config) {
97
98
  route.urlPath = route.urlPath.substring(0, route.urlPath.length - 1)
98
99
  }
99
100
  for (const method in route.handlers) {
100
- const theHandler = createHandler(route.handlers[method], route.middleware, route.pathParameters, config)
101
+ let theHandler = null
102
+ if (method === 'WEBSOCKET') {
103
+ theHandler = route.handlers[method]
104
+ } else {
105
+ theHandler = createHandler(route.handlers[method], route.middleware, route.pathParameters, config)
106
+ }
101
107
  app[appMethods[method]](route.urlPath, theHandler)
102
108
  if (hadSlash && config.serveRoutesWithSlash) {
103
109
  app[appMethods[method]](route.urlPath + '/', theHandler)