NestJs Body() is not populating with request information when coupled with serverless - serverless

When running SLS Offline or SLS Deploy the body decorator in nest isn't being populated with the object being passed.
I have assembled a small repo to investigate the issue for anyone interested.
https://gitlab.com/claridgicus/nest-serverless-body-issue
SLS Offline output
[Nest] 91880 - 2019-04-24 20:58 [ExceptionHandler] Map#toJSON isn't generic +5ms
TypeError: Map#toJSON isn't generic
at String.toJSON (c:\Users\Claridgicus\AppData\Roaming\npm\node_modules\serverless\node_modules\core-js\modules\_collection-to-json.js:6:38)
at Function.<anonymous> (c:\Users\Claridgicus\AppData\Roaming\npm\node_modules\serverless\node_modules\core-js\modules\_ctx.js:18:15)
at JSON.stringify (<anonymous>)
at Function.stringify [as default] (c:\Users\Claridgicus\code\serverless-nestjs-master\node_modules\fast-safe-stringify\index.js:11:18)
at ModuleTokenFactory.getDynamicMetadataToken (c:\Users\Claridgicus\code\serverless-nestjs-master\node_modules\#nestjs\core\injector\module-token-factory.js:20:69)
at ModuleTokenFactory.create (c:\Users\Claridgicus\code\serverless-nestjs-master\node_modules\#nestjs\core\injector\module-token-factory.js:12:27)
at ModuleCompiler.compile (c:\Users\Claridgicus\code\serverless-nestjs-master\node_modules\#nestjs\core\injector\compiler.js:19:47)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
1: std::vector<v8::CpuProfileDeoptFrame,std::allocator<v8::CpuProfileDeoptFrame> >::vector<v8::CpuProfileDeoptFrame,std::allocator<v8::CpuProfileDeoptFrame> >
2: v8::internal::wasm::SignatureMap::Find
3: v8::internal::Builtins::CallableFor
4: v8::internal::Builtins::CallableFor
5: v8::internal::Builtins::CallableFor
6: 0000006B886843C1

So
After much poking around - I double checked my headers on the incoming request
On the incoming POST request from the fed - Double check you are setting the headers - and save yourself the couple of hours unlike me :)
headers: {
"Content-Type": "application/json"
},

Related

Workbox cachefirst network request error with Giphy

I'm using the following strategy to cache images:
workbox.routing.registerRoute(
/.*\.(?:png|jpg|jpeg|svg|webp|gif)/,
new workbox.strategies.CacheFirst({
"cacheName": "images",
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 2592000,
purgeOnQuotaError: false})]
}), 'GET');
I'm not defining any other particular strategies.
When I try it in an index.html containing a Gif hosted by Giphy:
<img src="https://media.giphy.com/media/xUA7baWfTjfHGLZc3e/giphy.gif"/>
Worbox do seeems to cache properly as long as I'm online
Using CacheFirst to respond to 'https://media.giphy.com/media/xUA7baWfTjfHGLZc3e/giphy.gif'
If I disable my wifi and try to refresh offline my page I hit the following errors:
workbox Network request for 'https://media.giphy.com/media/xUA7baWfTjfHGLZc3e/giphy.gif' threw an error. TypeError: Failed to fetch
Uncaught (in promise) no-response: The strategy could not generate a response for 'https://media.giphy.com/media/xUA7baWfTjfHGLZc3e/giphy.gif'. The underlying error is TypeError: Failed to fetch.
at CacheFirst.makeRequest (https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-strategies.dev.js:180:15)
GET https://media.giphy.com/media/xUA7baWfTjfHGLZc3e/giphy.gif net::ERR_FAILED
Therefore am I missing something? Should I configure something more to be able to cache Giphy gifs? Or is it actually a bug? Or something which can't be solved?
Any help appreciated, thank you in advance
My question is a duplicate of Workbox Cache First not caching properly
The answer is the one provided by Diego H Ferraz in https://stackoverflow.com/a/59040270/5404186

Workbox Request method 'POST' is unsupported

I am using the code from this site: https://developers.google.com/web/tools/workbox/modules/workbox-routing
My code is as below:
workbox.routing.registerRoute(
new RegExp('http://localhost:64445.*/'),
workbox.strategies.staleWhileRevalidate({
cacheName:'Post-Run-time-cache'
}),
'POST'
);
And it gives me the error:
Uncaught (in promise) TypeError: Request method 'POST' is unsupported
I do not know what went wrong. It is from the document but it is not supported?? why. Thanks for the help.
The Cache Storage API doesn't support using a Request object whose method is not 'GET' as a cache key. Attempting to store a 'POST' request in the cache (which is happening under the hood in the staleWhileRevalidate strategy) will fail with an error similar to what you're seeing—though I think there's a more informative error logged when you're in Workbox's development mode, on localhost.
If you're looking to retry failed 'POST' requests, I'd recommend the workbox-background-sync module.

ZF2 - Apigility not creating new api

I have Apigility running successfully on an app and have decided to use it for a new one. The problem I am stumped with is that it refuses to create a new api and appears to "hang" on the "create new api" screen.
Here is a screenshot of where it hangs: http://screencast.com/t/7CI3TN38Fm
Any advise on how to bug test this or has anyone experienced similar issues?
EDIT
When checking the console I note the following errors:
http://screencast.com/t/gIbZEWMwo
http://cloud.examplesite.dev/apigility/api/fs-permissions Failed to load resource: the server responded with a status of 403 (Forbidden)
vendor-angular.js:2 TypeError: Cannot read property 'fs_perms' of undefined
at http://cloud.examplesite.dev/zf-apigility-admin/js/app.js:1:5838
at j (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:16336)
at http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:17013
at k.$eval (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:21222)
at k.$digest (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:19926)
at k.$apply (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:21541)
at f (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:2732)
at r (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:4556)
at XMLHttpRequest.w.onreadystatechange (http://cloud.examplesite.dev/zf-apigility-admin/js/vendor-angular.js:2:5095)vendor-angular.js:2 (anonymous function)
http://cloud.examplesite.dev/apigility/api/cache-enabled Failed to load resource: the server responded with a status of 403 (Forbidden)
3http://cloud.examplesite.dev/apigility/api/module Failed to load resource: the server responded with a status of 403 (Forbidden)
http://cloud.examplesite.dev/apigility/ui#/api Failed to load resource: net::ERR_CACHE_MISS
vendor-angular.js:2 GET http://cloud.examplesite.dev/apigility/api/dashboard 403 (Forbidden)
vendor-angular.js:2 GET http://cloud.examplesite.dev/apigility/api/dashboard 403 (Forbidden)
EDIT
After further investigation it would appear ZfcRbac is the cause of the problem... to create the Api it needs to be commented out.
Not sure of the best method to work around this... will investigate and post the answer once I know.
What I did to resolve this was to create an autoload file: mydev.local.php and to include the following in it:
<?php
return [
'zfc_rbac' => [
'protection_policy' => \ZfcRbac\Guard\GuardInterface::POLICY_ALLOW
]
Problem solved. thanks!
];
This means that any route that is not in my guards is not protected... of course when going to live mode, the local override file is not included...
If you update Apigility to the dev-master this issue will go away.
In your composer.json use this
"require-dev":{
"zfcampus/zf-apigility-admin": "dev-master"
}
and please disable opcache in php.ini also.

Newbie OAuth issue: Error when trying to use the PHPoAuthLib OAuth lib

I've got an issue using this OAuth lib when connecting with twitter:
https://github.com/Lusitanian/PHPoAuthLib
I'm using the following url to connect:
http://www.myserver.com/oauth/examples/twitter.php?go=go
I'm getting the following error:
Fatal error: Uncaught exception 'OAuth\Common\Http\Exception\TokenResponseException' with message 'file_get_contents(https://api.twitter.com/oauth/request_token): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized ' in /webDeploy/V2/sites/wandexBB/oauth/src/OAuth/Common/Http/Client/StreamClient.php:75 Stack trace: #0 /webDeploy/V2/sites/wandexBB/oauth/src/OAuth/OAuth1/Service/AbstractService.php(52): OAuth\Common\Http\Client\StreamClient->retrieveResponse(Object(OAuth\Common\Http\Uri\Uri), Array, Array) #1 /webDeploy/V2/sites/wandexBB/oauth/examples/twitter.php(59): OAuth\OAuth1\Service\AbstractService->requestRequestToken() #2 {main} thrown in /webDeploy/V2/sites/wandexBB/oauth/src/OAuth/Common/Http/Client/StreamClient.php on line 75
It looks like the request body is empty.
I see in the code the following params are being used:
$_GET['oauth_token'],
$_GET['oauth_verifier'],
What are these params? I see in my twitter account I have various tokens available after I created my app on twitter, is it something to do with that?
I'm lost :/ This could be the wrong approach altogether.
Can anyone help with this?
Thanks in advance.
This lib seems to have a bug relating to the twitter implementation. Now using a different lib and got that going much more easily:
https://github.com/sudocode/ohmy-auth

The endpoint reference (EPR) for the Operation not found is

I have been struggling with the following error the last couple of
days can you please help!
I generated my server and client code using the wsdl2java tool from a
wsdl 2.0 file.
When invoking the webservice I am getting the following error:
org.apache.axis2.AxisFault: The endpoint reference (EPR) for the
Operation not found is
/axis2/services/MyService/authentication/?username=Denise345&password=xxxxx
and the WSA Action = null
My service is displayed on the axis2 webpage with all available methods.
Here is the output from TcpMon
==============
Listen Port: 8090
Target Host: 127.0.0.1
Target Port: 8080
==== Request ====
GET /axis2/services/MyService/authentication/?username=Denise345&password=xxxxx
HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
SOAPAction: ""
User-Agent: Axis2
Host: 127.0.0.1:8090
==== Response ====
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: application/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 12 May 2011 15:53:20 GMT
Connection: close
12b
<soapenv:Reason xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Text xml:lang="en-US">The endpoint reference (EPR) for the
Operation not found is
/axis2/services/MyService/authentication/?username=Denise345&password=xxxxx
and the WSA Action = null</soapenv:Text></soapenv:Reason>
0
==============
I am using:
axis2-1.5.4
Tomcat 7.0.8
wsdl 2.0 file
Please help!
In my case it was caused by a wrong Content-Type in the HTTP POST. Setting it to text/xml solved the problem.
Try adding ?wsdl to the string.
As described by Eran Chinthaka at http://wso2.com/library/176/
If Axis2 engine cannot find a service and an operation for a message,
it immediately fails, sending a fault to the sender. If service not
found - "Service Not found EPR is " If
service found but not an operation- "Operation Not found EPR is and WSA Action = "
In your case the service is found but the operation not. The Axis2 engine uses SOAPAction in order to figure out the requested operation and, in your example, the SOAPAction is missing, therefore I would try to define the SOAPAction header
It happens because the source WSDL in each operation has not defined the SOAPAction value.
e.g.
<soap12:operation soapAction="" style="document"/>
His is important for axis server.
If you have created the service on netbeans or another, don't forget to set the value action on the tag #WebMethod
e.g. #WebMethod(action = "hello", operationName = "hello")
This will create the SOAPAction value by itself.
Action is null means that no Action in given SOAP Message (Request XML). You must set Action before SOAP call:
java.net.URL endpoint = new URL("<URL>"); //sets URL
MimeHeaders headers = message.getMimeHeaders(); // getting MIME Header
headers.addHeader("SOAPAction", "<SOAP Action>"); //add Action To Header
SOAPMessage response = soapConnection.call(<SOAPMessage>, endpoint); //then Call
soapConnection.close(); // then Close the connection
I had this same problem using curl to send a soap request. Solved it by adding "content-type: text/xml" to the http header.
I hope this helps someone.
This error is coming because while calling the service, it is not getting the WSDL file of your service.
Just check whether WSDL file of your service is there--> run server and from browser run axis 2 apps on local host and check the deployed services and click on your service, then it shows WSDL file of your service.....or check the service path in your client file.
I hope it may help you to resolve the problem.
This can be solved by disabling validation
<proxy>
<!-- . . . -->
<parameter name="disableOperationValidation">true</parameter>
</proxy>
Late answer but:
I see you do a GET - should be a POST ?
try removing the extra '/' after the operation name (authentication) when invoking through the client
/axis2/services/MyService/authentication?username=Denise345&password=xxxxx
It seems don't find wsdl file..
I've solved adding wsdlLocation parameter at javax.jws.WebService annotation
By removing cache wsdl-* files in /tmp folder, my problem was solved
see https://www.drupal.org/node/1132926#comment-6283348
be careful about permission to delete
I'm in ubuntu os
On Websphere Application Server, in the same situation, it helped deleting the Temp folders while the server was stopped.
I ran into the situation when the package of the service changed.
Open WSDL file and find:
<soap:operation soapAction="[actionNameIsHere]" style="document"/>
Add to the requests header [request send to service]:
'soapAction' : '[actionNameIsHere]'
This work for me.
For devs. using node-soap [ https://github.com/vpulim/node-soap ] - example:
var soap = require('soap');
var options = {
...your options...
forceSoap12Headers: true
}
soap.createClient(
wsdl, options,
function(err, client) {
if(err) {
return callBack(err, result);
}
client.addHttpHeader('soapAction', '[actionNameIsHere]');
...your code - request send...
});
I got this error because the SOAP request I was sending to the server was malformed and had an empty Body
In this case the error message from the server is misleading and can be solved changing the request content, without changing anything about operations, URLs, WSDL, etc

Resources