just-another-http-api 1.2.2 → 1.2.3

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.
Files changed (2) hide show
  1. package/api.js +11 -4
  2. package/package.json +2 -2
package/api.js CHANGED
@@ -109,17 +109,24 @@ function translateLegacyMethods ( method ) {
109
109
  }
110
110
 
111
111
  function fastifyHandlerWrapper ( handler, config, globalConfig, method ) {
112
- if ( config?.[ method ].websocket ){
112
+ if ( config?.[ method ]?.websocket ){
113
113
  return handler;
114
114
  }
115
115
  else {
116
116
  return async ( req, reply ) => {
117
117
  try {
118
- let response = await caching.checkRequestCache ( app, req, reply, config, globalConfig );
118
+ let response;
119
+ if ( globalConfig?.cache?.enabled ){
120
+ const request = { method: req.method, query: JSON.parse ( JSON.stringify ( req.query ) ), routeOptions: req.routeOptions };
121
+ response = await caching.checkRequestCache ( app, request, reply, config, globalConfig );
119
122
 
120
- if ( !response ){
123
+ if ( !response ){
124
+ response = await handler ( req );
125
+ await caching.setRequestCache ( app, request, response, config, globalConfig );
126
+ }
127
+ }
128
+ else {
121
129
  response = await handler ( req );
122
- await caching.setRequestCache ( app, req, response, config, globalConfig );
123
130
  }
124
131
 
125
132
  handleResponse ( reply, response, req.method, req.routeOptions.url );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-another-http-api",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "A framework built on top of fastify aimed at removing the need for any network or server configuration. ",
5
5
  "homepage": "https://github.com/OllieEdge/just-another-http-api#readme",
6
6
  "repository": {
@@ -43,4 +43,4 @@
43
43
  "eip-cloud-services": "^1.1.0",
44
44
  "mocha": "^10.2.0"
45
45
  }
46
- }
46
+ }