on localhost when I run the application the response I get from the endopoint GET /:id when I send an id it does not find is:
instead when I test it in the QA environment, mounted on a windows server is:
I would like it to be the JSON.
My code is:
controller.ts
#UseGuards(JwtAuthGuard)
getControlGroupTransition(#Param('id') id: number) {
if (isNaN(id)) {
throw new BadRequestException()
}
return this.controlGroupTransitionsService.getControlGroupTransition(id)
}
Related
I'm implementing Headless Wordpress using Faust.js and ran into a problem. The current Wordpress backend requires basic http authentication, protected by base64-encoded credentials, before being able to access the backend site contents and I'm running the frontend with Faust.js. On a local environment, there is no need to implement adding the credentials to the header but on production (because the http authentication exists), I can't retrieve the post content as well as other assets such as images, etc. from the Wordpress backend.
I was doing some research into how to add the http authentication but so far I've only found limited examples of how to implement basic authentication to do this. One is with typescript (https://github.com/wpengine/faustjs/issues/845) but since I currently have the project on js code, it seems I would need to convert a lot of the files into typescript (maybe including the packages included in node_modules which I don't want to break if I did the conversion). I want to find a way to add this http basic authentication as part of the request header on my Faust.js frontend project without converting to js.
On the example, I've tried implementing this with the ts example, while using js code, but I'm getting all sorts of errors, when building it. Here's the code:
import { IncomingMessage } from 'http';
import { getClient, logQueries } from '#faustjs/next';
import {
generatedSchema,
scalarsEnumsHash,
GeneratedSchema,
SchemaObjectTypes,
SchemaObjectTypesNames,
} from './schema.generated';
export const client = getClient({
GeneratedSchema,
SchemaObjectTypesNames,
SchemaObjectTypes,
schema: generatedSchema,
scalarsEnumsHash,
applyRequestContext: async (url, init) => {
const newInit = {
...init,
headers: {
...init.headers,
authorization: 'Basic YmxhbmtkZXhzaXRzdGc6OTMzODVlNjY=',
},
};
return { url, init: newInit };
},
});
export function serverClient(req) {
return getClient<GeneratedSchema, SchemaObjectTypesNames, SchemaObjectTypes>({
schema: generatedSchema,
scalarsEnumsHash,
context: req,
});
}
if (process.env.NODE_ENV === 'development') {
logQueries(client);
}
export * from './schema.generated';
The errors I'm getting when building it are among the following:
1:1 Error: There should be at least one empty line between import groups import/order
8:3 Error: GeneratedSchema not found in './schema.generated' import/named
9:3 Error: SchemaObjectTypes not found in './schema.generated' import/named
10:3 Error: SchemaObjectTypesNames not found in './schema.generated' import/named
I'm using node-soap to consume a WebService. I've used this library and consumed this service many times before, but this time I'm having the following situation.
I create the client using the WSDL that contains the methods, inputs etc:
const soap = require("soap");
const url = "https://servintp.latinoseguros.com.mx:8071/wsCotizadorAutos/cotizador/CotizadorLatino.svc?wsdl";
soap.createClient(url, {}, (error, client) => {
if (error) {
callback(error);
} else {
const describe = client.describe()["CotizadorLatino"]["BasicHttpBinding_ICotizadorLatino"];
console.log(describe["ObtenerMarcas"])
}
});
The request is successful and the client is created, but when I describe the method "ObtenerMarcas" I receive the following object:
{
input: { datos: 'q17:DatosRequeridos' },
output: { ObtenerMarcasResult: 'q18:ListMarca' }
}
Whose only input param shows as only a String, while it should be an object whith different objects and attributes.
When using Soap Client and inputing the exact same WSDL endpoint, the method is described as it should, with all the children and attributes that are expected to be passed:
Soap Client Screenshot
Which makes me believe that this has something to do with the client configuration or probably something very basic that I'm not taking into account.
Can anybody point me on what I'm doing wrong?
Thanks!
I am trying to intercept a PUT request using nock, but something is going really strange...
My code has 2 calls, a GET request
http://internal-jira.com/rest/api/2/issue/CCC-2142
and a PUT request with payload
http://internal-jira.com/rest/api/2/issue/CCC-2142
{ fields: { reporter: { name: '8778469' } } }
The process is that it does the GET then uses info from there to do the PUT.
So I have also created 2 mock calls, one for the GET
nock('http://internal-jira.com.com', {allowUnmocked: true}).persist()
.get(/\/rest\/api\/2\/issue\/.*/)
.reply(400, (uri) => {
console.log(`!!!! Mocked GET: ${uri} !!!`);
})
and one for the PUT
.put(/\/rest\/api\/2\/issue\/.*/)
.reply(400, (uri) => {
console.log(`!!!! Mocked PUT: ${uri} !!!`);
})
If the GET code is active and I run my code then I can see that the code is being caught as I get the console.log()
!!!! Mocked GET: /rest/api/2/issue/CCC-2144 !!!
But if I comment out the GET and enable the PUT when I run my code, it fails and errors at the GET without it being mocked.
Its as if the PUT mock, is somehow intercepting the GET request (I guess as the URL is the same) but not actually doing anything with it, but also not letting the GET request through?
What am I doing wrong?
I have written the piece of code below:
static async postSearchResult(httpContext: HttpContext, injector: Injector) {
const log = injector.get(Log);
const service = injector.get(Service);
try {
let result = await service.redirectToUI(JSON.parse(httpContext.getRequestBody()));
httpContext.ok(result, 200, {'Content-Type': 'application/json'});
} catch (e) {
httpContext.fail(e, 500);
}
}
protected redirectToUI(response: any) {
// If any post api call happened then it should open web browser and pass some field as query parameter
window.open("https://www.google.com?abc=response.abc");
return response ? response : "failed";
}
Here I am getting the following error :
Execution failed ReferenceError: Window is not defined
What am I doing wrong?
What you are trying to accomplish doesn't make much of a sense. Lambda is a back-end service. To open new browser window, you need to use front-end JavaScript, not back-end Node (on the back-end, you have no access to the front-end window object).
If you want to open a new browser window as a reaction to some back-end response, then you can send some indicator in the HTTP response (i.e shouldOpenNewWindow: true as a part of the response object), parse that response on the front-end and it the indicator is present, then you can issue window.open command. But it has to be done on front-end.
I'm running into an odd issue with Pact-js and POST bodies.
The background:
Consumer Side
- I have a NodeJs app which I'm trying to test
- I configured Pact and set up the appropriate framework
- All test run successfully and generate contract
Provider Side:
- Again, I have a NodeJs app which I'm trying to test
- Pact has been set up and framework in place
- When i run the test, all GET requests run successfully, however all POSTs report a fail.
The Issue:
- When I echo out the POST body being passed to the service from Pact (veryifyProvider), i can see that its wrapped the body (JSON) inside another 'Key: value' pairing, where the body i want to parse is the Key and the value is empty. Its also added escape chars ( \ ) to all the double quotes inside the Body.
EX:
{"{\"Account\":\"123\",\"Orbit\":\"5.00\",\"Date\":\"2016-06-22\",\"Client\":\"1234\",\"Spring\":\"1234\"}":""}
When i look in my Pact contract json, everything looks correct. Somewhere between VerifyProvider reading in the JSON and passing it to the REST endpoint, the body is mangled. This only seam to happen during tests, normal invocation works appropriately.
Here is the code I'm using Provider side to execute the Verify:
const verifier = require('pact').Verifier;
const path = require('path');
let contract = path.join(__dirname, 'pactContract.json');
let opts = {
providerBaseUrl: "http://localhost:3001",
pactUrls: [contract],
};
verifier.verifyProvider(opts)
.then((res) => {
console.log('pact veryify complete, !!!');
console.log(res);
process.exit(0);
}).catch((error) => {
console.log(error);
process.exit(1);
});
I'm unable to pull down my exact consumer codebase, but its nearly identical in structure shown here Pact-js.
Any help is VERY much appreciated!
Please check the Content-Type header and ensure it is application/json. This can happen if the service thinks it's matching text messages.