Open joain946 opened 3 years ago
Please provide a minimum reproduction repository.
Repository: https://github.com/joain946/nestjs-azure
Any update on this @kamilmysliwiec? Do you need any additional input from me?
I am having the exact same issue, none of the nestjs headers are being sent to the azure function only stock azure response headers. Ran the code from git and npm and having same issue.
Seems like the writeHead bound function is never getting called, breakpoint not getting hit in bound function. this.writeHead = this.writeHead.bind(this, context);
Info: azure functions v3
Interesting Note
When using AzureHttpRouter const app = await NestFactory.create(AppModule, new AzureHttpRouter());
The some headers seem to be sent , most notably 'content-type'
Ive just hit this exact same issue. Has there been any movement on this.? Only way i can currently work arouns it is remove my app.enableCors() ( as this conflicts with the adapter ) and override the HttpAdapters context
Hello everyone
@nlaurie @gristoi Did you find a workaround ? @kamilmysliwiec How can we help debugging it?
We are stuck with the exact same issue.
Thank you
Felix
Hello everyone,
I've found a simple workaround. Please try this.
Thank you.
import { Context, HttpRequest } from '@azure/functions';
import { AzureHttpAdapter } from '@nestjs/azure-func-http';
import { createApp } from '../src/main.azure';
function createPsuedoApp(createApp: () => Promise<any>): () => Promise<any> {
return async (): Promise<any> => {
const app = await createApp();
const psuedoApp = {
getHttpAdapter: () => {
return {
getInstance: () => {
return (req: any, res: any) => {
const done = req.context.done;
req.context.done = (err?: string | Error, result?: any) => {
res.writeHead();
done(err, result);
};
app.getHttpAdapter().getInstance()(req, res);
};
},
};
},
};
return psuedoApp;
};
}
export default function(context: Context, req: HttpRequest): void {
AzureHttpAdapter.handle(createPsuedoApp(createApp), context, req);
}
Would be nice to have a pull request to fix it within azure-func-http.
We solved thia on host.json file..
{ "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[2.*, 3.0.0)" }, "functionTimeout": "01:00:00", "extensions": { "http": { "routePrefix": "api", "customHeaders": { "Content-Type": "application/json" } } } }
All we needed is json response header..
We are using microsoft docker's img to emulate in local environment.
Hello everyone,
I've found a simple workaround. Please try this.
Thank you.
import { Context, HttpRequest } from '@azure/functions'; import { AzureHttpAdapter } from '@nestjs/azure-func-http'; import { createApp } from '../src/main.azure'; function createPsuedoApp(createApp: () => Promise<any>): () => Promise<any> { return async (): Promise<any> => { const app = await createApp(); const psuedoApp = { getHttpAdapter: () => { return { getInstance: () => { return (req: any, res: any) => { const done = req.context.done; req.context.done = (err?: string | Error, result?: any) => { res.writeHead(); done(err, result); }; app.getHttpAdapter().getInstance()(req, res); }; }, }; }, }; return psuedoApp; }; } export default function(context: Context, req: HttpRequest): void { AzureHttpAdapter.handle(createPsuedoApp(createApp), context, req); }
Only quoting to appoint the file where you need to edit. Add this script on main/index.ts
.
Hello everyone,
I have the same problem, will it be resolved?
Somehow this script solves the header problem, but misses the 302 status, making it 200. Any way to keep the status and have the Location header?
I'm submitting a...
Current behavior
Response headers are not sent back to the client. The example below returns this response:
Expected behavior
All response headers should be returned to the client. From the example below the "Content-Type" and "MyHeader" header should have been returned from the REST api.
Minimal reproduction of the problem with instructions
Using this instruction: https://trilon.io/blog/deploy-nestjs-azure-functions Then adding two @Header() decorators to the api:
Environment
Workaround
It seems like the writeHead(...) method is never called. Triggering this method from IDE or through code (in an interceptor) solves the issue.