GithubHelp home page GithubHelp logo

Comments (13)

kniwase avatar kniwase commented on April 24, 2024 10

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);
}

from azure-func-http.

brunoog33 avatar brunoog33 commented on April 24, 2024 2

Hello everyone,

I have the same problem, will it be resolved?

from azure-func-http.

gristoi avatar gristoi commented on April 24, 2024 1

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

from azure-func-http.

OskarsPakers avatar OskarsPakers commented on April 24, 2024 1

Would be nice to have a pull request to fix it within azure-func-http.

from azure-func-http.

kamilmysliwiec avatar kamilmysliwiec commented on April 24, 2024

Please provide a minimum reproduction repository.

from azure-func-http.

joain946 avatar joain946 commented on April 24, 2024

Repository: https://github.com/joain946/nestjs-azure

from azure-func-http.

joain946 avatar joain946 commented on April 24, 2024

Any update on this @kamilmysliwiec? Do you need any additional input from me?

from azure-func-http.

nlaurie avatar nlaurie commented on April 24, 2024

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.

image

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

from azure-func-http.

nlaurie avatar nlaurie commented on April 24, 2024

Interesting Note

When using AzureHttpRouter
const app = await NestFactory.create(AppModule, new AzureHttpRouter());

The some headers seem to be sent , most notably 'content-type'

from azure-func-http.

sportelli avatar sportelli commented on April 24, 2024

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

from azure-func-http.

KaduMoura avatar KaduMoura commented on April 24, 2024

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.

from azure-func-http.

tiagoboeing avatar tiagoboeing commented on April 24, 2024

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.

from azure-func-http.

qstyler avatar qstyler commented on April 24, 2024

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?

from azure-func-http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.