nestjs / azure-func-http Goto Github PK
View Code? Open in Web Editor NEWAzure Functions HTTP adapter for Nest framework (node.js) ๐ฅ
Home Page: https://nestjs.com/
License: MIT License
Azure Functions HTTP adapter for Nest framework (node.js) ๐ฅ
Home Page: https://nestjs.com/
License: MIT License
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
On Monorepo project, I can't create multiple functions based on my apps.
Ability to use azure-http-func on Monorepo Mode projects to create multiple functions.
Create a new NestJS project using CLI nest new my-project
Create a Monorepo adding new app with nest g app my-app
Add azure-http-func to the first app: nest add @nestjs/azure-func-http --rootDir apps/my-project/src
.
3.1. Select my-project project to add library to.
At this point everything works fine.
Try add azure-http-func to the second app: nest add @nestjs/azure-func-http --rootDir apps/my-app/src
.
4.1. Select my-app project to add library to.
We are presented the following error:
โฏ nest add @nestjs/azure-func-http --rootDir apps/my-app/src
โ Package installation in progress... โ
? Which project would you like to add the library to? my-app
Starting library setup...
ERROR! .funcignore already exists.
ERROR! host.json already exists.
ERROR! local.settings.json already exists.
ERROR! proxies.json already exists.
ERROR! main/function.json already exists.
ERROR! main/index.ts already exists.
ERROR! main/sample.dat already exists.
The Schematic workflow failed. See above.
Failed to execute command: "/home/danilo/Projects/my-project/node_modules/.bin/schematics" @nestjs/azure-func-http:nest-add --sourceRoot="apps/my-app/src" --rootDir apps/my-app/src
I want to create a Monorepo with multiple apps and split my API into separated Azure Functions.
Nest version: 7.2.0
For Tooling issues:
- Node version: v12.17.0
- Platform: Linux
Currently I can see one index.ts inside Main folder which has code like
export default function(context: Context, req: HttpRequest): void { AzureHttpAdapter.handle(createApp, context, req); }
If I have another azure function in same app, what is the recommended approach? See the below code which we have in .NetCore
`
public static class ClientInfoFuncion
{
[FunctionName("IP")]
public static IActionResult GetClientIp(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("Requesting client IP.");
var ip = req.HttpContext.Connection.RemoteIpAddress.ToString();
return ip != null
? (ActionResult)new OkObjectResult($"{ip}")
: new BadRequestObjectResult("ip is null");
}
[FunctionName("UserAgent")]
public static IActionResult GetClientUserAgent(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("Requesting client User-Agent.");
var ua = req.Headers["User-Agent"].ToString();
return ua != null
? (ActionResult)new OkObjectResult($"{ua}")
: new BadRequestObjectResult("user-agent is null");
}
}
`
Hi Nest.js team! I'm running into the following issue while using this package. Thanks in advance for your help! I'm really loving nest.js so far and really looking forward to getting my project working on an azure function app!
[ ] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
AzureHttpRouter constructor is throwing an exception:
[2022-11-15T15:44:11.885Z] Executing HTTP request: {
[2022-11-15T15:44:11.885Z] requestId: "da9a6aa2-4bcc-42a2-8f2d-f3969f01ecf4",
[2022-11-15T15:44:11.885Z] method: "GET",
[2022-11-15T15:44:11.886Z] userAgent: "PostmanRuntime/7.28.4",
[2022-11-15T15:44:11.886Z] uri: "/"
[2022-11-15T15:44:11.886Z] }
[2022-11-15T15:44:11.973Z] Executing 'Functions.main' (Reason='This function was programmatically called via the host APIs.', Id=12eac574-6fe4-49dd-baee-619866eb4be0)
[2022-11-15T15:44:12.006Z] Received FunctionInvocationRequest
[2022-11-15T15:44:12.006Z] (node:1922) UnhandledPromiseRejectionWarning: TypeError: trouter_1.default is not a constructor
[2022-11-15T15:44:12.006Z] at new AzureHttpRouter (/Users/siddharthkapoor/Desktop/projects/OdapCloud/odap/node_modules/@nestjs/azure-func-http/dist/router/azure-http.router.js:12:15)
[2022-11-15T15:44:12.006Z] at createApp (/Users/siddharthkapoor/Desktop/projects/OdapCloud/odap/dist/src/main.azure.js:8:73)
[2022-11-15T15:44:12.006Z] at AzureHttpAdapterStatic.<anonymous> (/Users/siddharthkapoor/Desktop/projects/OdapCloud/odap/node_modules/@nestjs/azure-func-http/dist/azure-http.adapter.js:24:31)
[2022-11-15T15:44:12.006Z] at Generator.next (<anonymous>)
[2022-11-15T15:44:12.006Z] at /Users/siddharthkapoor/Desktop/projects/OdapCloud/odap/node_modules/@nestjs/azure-func-http/dist/azure-http.adapter.js:8:71
[2022-11-15T15:44:12.006Z] at new Promise (<anonymous>)
[2022-11-15T15:44:12.006Z] at __awaiter (/Users/siddharthkapoor/Desktop/projects/OdapCloud/odap/node_modules/@nestjs/azure-func-http/dist/azure-http.adapter.js:4:12)
[2022-11-15T15:44:12.006Z] at AzureHttpAdapterStatic.createHandler (/Users/siddharthkapoor/Desktop/projects/OdapCloud/odap/node_modules/@nestjs/azure-func-http/dist/azure-http.adapter.js:23:16)
[2022-11-15T15:44:12.006Z] at AzureHttpAdapterStatic.handle (/Users/siddharthkapoor/Desktop/projects/OdapCloud/odap/node_modules/@nestjs/azure-func-http/dist/azure-http.adapter.js:20:14)
[2022-11-15T15:44:12.006Z] at Object.run (/Users/siddharthkapoor/Desktop/projects/OdapCloud/odap/dist/main/index.js:7:40)
I added dded @nestjs/azure-func-http to my project via nest cli. Added the AzureHttpRouter constructor into main.azure.ts as per documentation:
export async function createApp(): Promise<INestApplication> {
const app = await NestFactory.create(AppModule, new AzureHttpRouter());
// app.setGlobalPrefix('api');
await app.init();
return app;
}
Everything works fine if I don't use the AzureHttpRouter (i.e. using express instead), but I would like to be able to use it for faster routing.
I dug into the package, and observed the following code in dist/router/azure-http.router.ts
// at line 8
const trouter_1 = require("trouter");
const adapter_1 = require("../adapter");
class AzureHttpRouter extends core_1.AbstractHttpAdapter {
constructor() {
super(new trouter_1.default()); // <-- this is where the exception occurs
this.routerMethodFactory = new router_method_factory_1.RouterMethodFactory();
}
Everything works as expected if I change the above code as follows:
const trouter_1 = require("trouter");
const adapter_1 = require("../adapter");
class AzureHttpRouter extends core_1.AbstractHttpAdapter {
constructor() {
super(new trouter_1()); // <-- just removed default
this.routerMethodFactory = new router_method_factory_1.RouterMethodFactory();
}
new AzureHttpRouter()
should not throw exception.
npm run build
func host start --verbose
I experienced some issues at this point. Dist folder showed a single compiled main.js file, and the func logging complained that the scriptFile was not found. So I had to set the webpack config in nest-cli.json off (to get the dist/main/index.js file specified in the auto-generated main/function.json file) to get things working.
[ X] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Trying to install the package fails with following error:
Starting library setup...
Error: NOT SUPPORTED: keyword "id", use "$id" for schema ID
at Object.code (/Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/vocabularies/core/id.js:6:15)
at keywordCode (/Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/validate/index.js:454:13)
at /Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/validate/index.js:222:17
at CodeGen.code (/Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/codegen/index.js:439:13)
at CodeGen.block (/Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/codegen/index.js:568:18)
at iterateKeywords (/Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/validate/index.js:219:9)
at groupKeywords (/Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/validate/index.js:208:13)
at /Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/validate/index.js:192:13
at CodeGen.code (/Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/codegen/index.js:439:13)
at CodeGen.block (/Users/johanvrolix/Sites/laviejoly/api/node_modules/ajv/dist/compile/codegen/index.js:568:18)
Failed to execute command: node @nestjs/azure-func-http:nest-add --sourceRoot="src" /usr/local/Cellar/[email protected]/14.18.1/bin/node /usr/local/bin/nest add @nestjs/azure-func-http
package to be installed and Azure function to be set up.
nest add @nestjs/azure-func-http
Nest version: 8.1.5
For Tooling issues:
- Node version: v14.18.1
- Platform: Mac
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
AzureHttpRouter tries to instantiateTRouter
but it's constructor is undefined
at runtime.
dist/router/azure-http.router.js
class AzureHttpRouter extends core_1.AbstractHttpAdapter {
constructor() {
super(new trouter_1.default());
this.routerMethodFactory = new router_method_factory_1.RouterMethodFactory();
}
logs error
[2021-08-09T07:02:24.228Z] (node:2928) UnhandledPromiseRejectionWarning: TypeError: trouter_1.default is not a constructor
[2021-08-09T07:02:24.231Z] at new AzureHttpRouter (C:\Users\rim\DEV\reproduction-nest-azure-http-issue-636\node_modules\@nestjs\azure-func-http\dist\router\azure-http.router.js:12:15)
[2021-08-09T07:02:24.235Z] at createApp (C:\Users\rim\DEV\reproduction-nest-azure-http-issue-636\dist\src\main.azure.js:8:73)
[2021-08-09T07:02:24.238Z] at AzureHttpAdapterStatic.<anonymous> (C:\Users\rim\DEV\reproduction-nest-azure-http-issue-636\node_modules\@nestjs\azure-func-http\dist\azure-http.adapter.js:24:31)
[2021-08-09T07:02:24.241Z] at Generator.next (<anonymous>)
[2021-08-09T07:02:24.243Z] at C:\Users\rim\DEV\reproduction-nest-azure-http-issue-636\node_modules\@nestjs\azure-func-http\dist\azure-http.adapter.js:8:71
[2021-08-09T07:02:24.246Z] at new Promise (<anonymous>)
[2021-08-09T07:02:24.249Z] at __awaiter (C:\Users\rim\DEV\reproduction-nest-azure-http-issue-636\node_modules\@nestjs\azure-func-http\dist\azure-http.adapter.js:4:12)
[2021-08-09T07:02:24.251Z] at AzureHttpAdapterStatic.createHandler (C:\Users\rim\DEV\reproduction-nest-azure-http-issue-636\node_modules\@nestjs\azure-func-http\dist\azure-http.adapter.js:23:16)
[2021-08-09T07:02:24.252Z] at AzureHttpAdapterStatic.handle (C:\Users\rim\DEV\reproduction-nest-azure-http-issue-636\node_modules\@nestjs\azure-func-http\dist\azure-http.adapter.js:20:14)
[2021-08-09T07:02:24.254Z] at Object.default_1 [as default] (C:\Users\rim\DEV\reproduction-nest-azure-http-issue-636\dist\main\index.js:6:40)
Instantiating Trouter
should work.
This issue seems more related to TRouter package.
Using the code snippet below works properly and does not require esModuleInterrop
.
import * as TRouter from "trouter";
//@ts-ignore
const R = new TRouter();
Fix a bug.
Nest version: 8.0.0
nest/azure-http-func version : 0.7.0
For Tooling issues:
- Node version: v14.16.0
- Platform: Mac
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Follow-up to #78.
Any request providing body that is not JSON (see #78) is failing (POST, PUT) due to the fact that express middleware expect an open stream for the request, and currently it received an event emitter through azure-function-express
wrapper.
Any kind of valid request should be processable like a regular NestJS app.
See #78
Support file upload, form-encoded data...
Nest version: 6.12.2
For Tooling issues:
- Node version: 12.13.0
- Platform: Mac
Others:
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
When we send a response on an endpoint we expect to receive the content-type: application/json when running the application as azure function but we are not receiving the content-type.
Preserve the header content-type sent by nest app.
Create a nest app install the azure-func-http and send a response as JSON. Run the azure function app locally to see if the content-type: application/json are preserved.
Preserve headers sent by NEST App.
Nest version: 8.0.0
For Tooling issues:
- Node version: 14
- Platform: Mac and Windows
Others:
Visual Code Studio
[ ] Regression
[ ] Bug report
[ ] Feature request
[ x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
using the swagger module with azure fx (express) requires several things be in sync:
app.init seems to be 100% required to work.
app.listen seems to be essential to getting swagger to work on the same port. Please encapsulate this behavior.
[]1. (https://trilon.io/blog/deploy-nestjs-azure-functions)
2. then add your openapi module and configure it.
do more with less.
Nest version: X.Y.Z
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Iam trying to follow the example here https://trilon.io/blog/deploy-nestjs-azure-functions
for azure functions deployment, however I keep getting this error
$ nest add @nestjs/azure-func-http
โ Installation in progress... โ
Error: Option "rootDir" is not defined.
at C:\Users\hemed\Desktop\_coreteck\gray\pos-system-backend\node_modules\@angular-devkit\schematics\src\rules\template.js:85:27
at C:\Users\hemed\Desktop\_coreteck\gray\pos-system-backend\node_modules\@angular-devkit\schematics\src\rules\base.js:109:30
at C:\Users\hemed\.npm-global\node_modules\@nestjs\cli\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:233:13
at C:\Users\hemed\.npm-global\node_modules\@nestjs\cli\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:41:59
at Array.forEach ()
at HostDirEntry.visit (C:\Users\hemed\.npm-global\node_modules\@nestjs\cli\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:41:43)
at HostCreateTree.visit (C:\Users\hemed\.npm-global\node_modules\@nestjs\cli\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:232:19)
at C:\Users\hemed\Desktop\_coreteck\gray\pos-system-backend\node_modules\@angular-devkit\schematics\src\rules\base.js:105:14
at MergeMapSubscriber.project (C:\Users\hemed\Desktop\_coreteck\gray\pos-system-backend\node_modules\@angular-devkit\schematics\src\rules\call.js:74:24)
at MergeMapSubscriber._tryNext (C:\Users\hemed\Desktop\_coreteck\gray\pos-system-backend\node_modules\@angular-devkit\schematics\node_modules\rxjs\internal\operators\mergeMap.js:69:27)
Nest version: 7.0.3
For Tooling issues:
- Node version: 12.14
- Platform: Windows
Others:
package manager: yarn
[ ] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Running with azure-func-http the class-validator module is not working, that is the request are not validated.
As same as the express nest module the request must be validated when i use class-validator module.
The following class is defined:
export class TestProductIdQueryDto {
@IsDefined()
@IsEnum(AtarProductId)
@ApiProperty({
enum: TestProductId,
})
productId: keyof typeof TestProductId;
}
When the request is made without productId on query should return a bad request.
I think class-validator is a good feature witch I can not use because when I add azure-func-http it's becomes incompatible.
Nest version: 8.0.0
For Tooling issues:
- Node version: 14.17.5
- Platform: Mac
Others:
- Azure func: 3.0.3904
- @nestjs/azure-func-http: 0.8.0
- class-validator: 0.13.2,
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
If I use the cookie-parser middleware or if I try to enable cors, I get this error:
[20.04.2020 12:42:56] TypeError: str.split is not a function
[20.04.2020 12:42:56] at module.exports (censored\api\node_modules\regexparam\dist\regexparam.js:3:53)
[20.04.2020 12:42:56] at Trouter.use (censored\api\node_modules\trouter\index.js:21:27)
[20.04.2020 12:42:56] at AzureHttpRouter.use (censored\api\node_modules\@nestjs\core\adapters\http-adapter.js:11:30)
[20.04.2020 12:42:56] at AzureHttpRouter.enableCors (censored\api\node_modules\@nestjs\azure-func-http\dist\router\azure-http.router.js:39:14)
[20.04.2020 12:42:56] at NestApplication.enableCors censored\api\node_modules\@nestjs\core\nest-application.js:136:26)
[20.04.2020 12:42:56] at exceptions_zone_1.ExceptionsZone.run (censored\api\node_modules\@nestjs\core\nest-factory.js:111:40)
[20.04.2020 12:42:56] at Function.run (censored\api\node_modules\@nestjs\core\errors\exceptions-zone.js:8:13)
[20.04.2020 12:42:56] at Proxy.args (censored\api\node_modules\@nestjs\core\nest-factory.js:110:46)
[20.04.2020 12:42:56] at createApp (censored\api\dist\src\app.fabric.js:13:9)
[20.04.2020 12:42:56] at process._tickCallback (internal/process/next_tick.js:68:7)
Should apply the middleware and enable cors. If I use express as router, it works.
Minimal reproduction repository can be found here:
https://github.com/Syntarex/minimal-reproduction-str-split
Start with npm run start
Look in src/app.fabric.ts
Nest version: 7.0.7
For Tooling issues:
- Node version: 10.19.0
- Platform: Windows 10
Is there a reason this project has the following as hard dependencies?
Could you make them dev dependencies instead?
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
When enabling AzureHttpRouter with const app = await NestFactory.create(AppModule, new AzureHttpRouter());
, all requests with a query param fail with a 404.
Same behavior as when using express router.
nest new bug
nest add @nestjs/azure-func-http
const app = await NestFactory.create(AppModule, new AzureHttpRouter());
npm run start:azure
curl http://localhost:7071/api/?test=1
fail, while curl http://localhost:7071/api/
worksUsing routes with query params.
Nest version: 6.12.2
For Tooling issues:
- Node version: 12.13.0
- Platform: Mac
Others:
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
When using the npm run start:azure
entry point or deploy my app on Functions, POST requests are not working. Using the regular entry point npm start
, requests works well.
POST requests works the same using azure functions entry points or the regular one.
npm start:azure
But really, this can be reproduced with any project and POST requests. (GET requests works fine)
Nest version: 6.10.12
For Tooling issues:
- Node version: 12.13.0
- Platform: Mac
Others:
[ ] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
After setting up a monorepo project with some libraries and an application, when I run npm run start:azure
I get the following error:
[3/15/20 5:22:56 PM] 0 proxies loaded
[3/15/20 5:22:56 PM] Generating 0 job function(s)
[3/15/20 5:22:56 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
[3/15/20 5:22:56 PM] Initializing function HTTP routes
[3/15/20 5:22:56 PM] No HTTP routes mapped
[3/15/20 5:22:56 PM]
[3/15/20 5:22:56 PM] Host initialized (589ms)
[3/15/20 5:22:56 PM] Host started (595ms)
[3/15/20 5:22:56 PM] Job host started
[3/15/20 5:22:56 PM] The 'main' function is in error: Invalid script file name configuration. The 'scriptFile' property is set to a file that does not exist.
Hosting environment: Production
Content root path: ...
Now listening on: http://0.0.0.0:7071
I also notice it's the regular main.ts that gets compiled with webpack, not the main.azure.ts
Nest version: 7.0.0
@nestjs/azure-func-http: 0.5.0
[ ] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
The @nestjs\azure-func-http\dist\router\azure-http.router.d.ts
type definition is missing the getRequestHostname
function declared in AbstractHttpAdapter
. It is however, present in lib/router/azure-http.router.ts
. If I manually add it, it all builds and runs just fine.
I'm thinking a build/publish might have gone wrong?
Nest version: 6.10.14
For Tooling issues:
- Node version: v12.14.1
- Platform: Windows
Others:
- @nestjs/azure-func-http version: 0.4.1
(also present in 0.4.0, 0.3.2, haven't tested further back as the property didn't exist back then in AbstractHttpAdapter)
[ ] Regression
[*] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
When I try to install NestJS Azure functions schematics to any app in a monorepo created using the cli, I get the following error:
Should create main.azure.ts and other files as shown here.
nest new my-app
cd micro2
nest generate app micro2
cd apps\micro2
nest add @nestjs/azure-func-http
Building and deploy multiple azure functions from a single monorepo.
Nest version: 6.7.2
For Tooling issues:
- Node version: 10.17.0
- Platform: Windows
Others:
[ ] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
In the Azure function handler, createApp with
const app = await NestFactory.create(AppModule, { cors: true });
When calling the Azure function running locally, a HTTP OPTIONS request to the /restapi - it should return the CORS headers.
Running the NestJS server directly (in express mode)
curl -vvv -X OPTIONS http://myserver:3333/restapi
returns CORS headers
But when running under func start
curl -vvv -X OPTIONS http://myserver:7071/restapi
should return the CORS accept header response.
No headers are returned.
Nest version: X.Y.Z
For Tooling issues:
- Node version: 14
- Platform: Mac
- Azure Function 4.0.0
- @nestjs/azure-func-http:^0.8.0
- @nestjs/platform-express:^8.0.0
- express: 4.17.1
Others:
Sharing investigation if it helps.
The default CORS handling in the express router - wraps the done with a check to handle OPTIONS
[email protected]/node_modules/express/lib/router/index.js
line 162
// for options requests, respond with a default if nothing else responds
if (req.method === 'OPTIONS') {
done = wrap(done, function(old, err) {
if (err || options.length === 0) return old(err);
sendOptionsResponse(res, options, old);
});
}
This method is not called by the Azure HTTP handler - so the default CORS handling for OPTIONS does not get invoked.
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
if in a nestjs monorepo I run the nest add @nestjs/azure-func-http
it asks for destination project and creates a azure function for it but if you run in twice it overrides the existing azure function to use the new project
running nest add @nestjs/azure-func-http
and selecting different projects should create multiple azure functions
nest new demo
cd demo
nest generate app models
nest add @nestjs/azure-func-http (select demo project)
nest add @nestjs/azure-func-http (select models project)
I'd like to use one repo for multiple azure functions
Nest version: 8.2.8
For Tooling issues:
- Node version: 16
- Platform: Mac
Others:
[ ] Regression
[x] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request
When creating an app with the AzureHttpRouter
, routing does not work.
In the README, it shows you can instantiate the app using an azure http router instead of the default express router. However, when adding this: const app = await NestFactory.create(AppModule, new AzureHttpRouter());
the request to any endpoint just hangs.
Perhaps I need to do something else to get this to work?
Also, when I use this with Typescript, and run build
, it says that AzureHttpRouter
is not being exported from the @nestjs/azure-func-http
package.
yarn add @nestjs/azure-func-http
main.azure.[j/t]s
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { AzureHttpRouter } from '@nestjs/azure-func-http'
export async function createApp() {
const app = await NestFactory.create(AppModule, new AzureHttpRouter());
app.setGlobalPrefix('webhooks');
await app.init();
return app;
}
Nest version: 6.8.3
For Tooling issues:
- Node version: 10.16.2
- Platform: Linux
Others:
[x] Bug report
Response headers are not sent back to the client.
The example below returns this response:
HTTP/1.1 200 OK
Date: Tue, 10 Nov 2020 12:39:58 GMT
Server: Kestrel
Content-Length: 12
Hello World!
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.
Using this instruction:
https://trilon.io/blog/deploy-nestjs-azure-functions
Then adding two @Header() decorators to the api:
import { Controller, Get, Header } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
@Header("Content-Type", "text/plain")
@Header("MyHeader", "MyHeaderValue")
getHello(): string {
return this.appService.getHello();
}
}
Nest version: 7.4.4
For Tooling issues:
- Node version: v12.18.0
- Platform: Windows
It seems like the writeHead(...) method is never called.
Triggering this method from IDE or through code (in an interceptor) solves the issue.
When doing npm run build && func host start I get the following error:
Warning: Proxies are not supported in Azure Functions v4. Instead of 'proxies.json', try Azure API Management: https://aka.ms/AAfiueq
After trying to access the endpoint, for example: https://nestjstest1.azurewebsites.net/api
I get the following error:
Server Error
502 - Web server received an invalid response while acting as a gateway or proxy server.
There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.
Please add Azure Functions v4 support, which has been out since last year.
Reference:
https://techcommunity.microsoft.com/t5/apps-on-azure-blog/azure-functions-v4-versus-v3/ba-p/3276055
[ ] Bug report
I have an Ionic project and a NestJs project integrated with azure-func-http. I am also using socket.io to make realtime communication between them. But socket.io is not working. Its working with the default NestJs project but not with the azure-func-http.
When I run locally I face:
Access to XMLHttpRequest at 'http://localhost:7071/socket.io/?EIO=3&transport=polling&t=N6eYJqK' from origin 'http://localhost:8100' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
When I run with the deployed one(deployed to Azure function with service plan where Websocket is turned on) I face:
GET https://my-nestjs-deployed-url/socket.io/?EIO=3&transport=polling&t=N6eYhXI 404 (Not Found)
I have tried to add the path and many other solutions. Nothing is working.
Communication via socket.io should be working
Here are the repositories where you can reproduce the issue:
Frontend Ionic project: https://github.com/ahsanhabib23/ionic-azurefunction-socketio-testing
Backend NestJs project: https://github.com/ahsanhabib23/nestjs-azurefunction-socketio-testing
Nest info:
[System Information]
OS Version : macOS Catalina
NodeJS Version : v12.16.1
NPM Version : 6.14.4
[Nest CLI]
Nest CLI Version : 7.1.2
[Nest Platform Information]
platform-socket.io version : 7.0.8
platform-express version : 7.0.0
azure-func-http version : 0.5.0
websockets version : 7.0.8
common version : 7.0.0
core version : 7.0.0
Ionic Info:
Ionic:
Ionic CLI : 6.6.0 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.0.7
@angular-devkit/build-angular : 0.803.26
@angular-devkit/schematics : 8.3.26
@angular/cli : 8.3.26
@ionic/angular-toolkit : 2.2.0
Utility:
cordova-res (update available: 0.13.0) : 0.9.0
native-run (update available: 1.0.0) : 0.3.0
System:
NodeJS : v12.16.1 (/usr/local/bin/node)
npm : 6.14.4
OS : macOS Catalina
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
We are currently using the same source for a local deployment (main.ts) and also an Azure deployment (main.azure.ts)
Swagger is working as expected with the installed node version (node dist/src/main.js) but is not working using the installed Azure Functions Core Tools (func host start --useHttps --cors * --verbose).
If is started using local azure functions files are not loaded as seen in the following image.
Should show the UI without problems as seen below:
import { NestFactory, HttpAdapterHost } from '@nestjs/core';
import { INestApplication, RequestMethod } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
import helmet from 'helmet';
import { AllExceptionsFilter } from './base/all-exceptions.filter';
import * as databases from './config/databases';
import { BackendHandshakeDto } from './globals/dto/backend-handshake-dto';
import { VersioningType } from '@nestjs/common';
export async function createApp(): Promise<INestApplication> {
const handshake: BackendHandshakeDto = new BackendHandshakeDto();
const app = await NestFactory.create(AppModule);
app.use(helmet());
app.enableCors();
app.use((request, response, next) => {
response.header('Access-Control-Allow-Origin', '*');
response.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
response.header('Access-Control-Allow-Headers', 'Content-Type, Accept');
next();
});
app.enableVersioning({
defaultVersion: '1',
type: VersioningType.URI,
});
app.setGlobalPrefix('api');
const options = new DocumentBuilder()
.setTitle('TUNNEL:Manager API')
.setDescription(
`API for TUNNEL:Manager App
Supported database versions: ${databases.default.supportedVersions()}`,
)
.setVersion(handshake.backendVersion)
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api-docs', app, document, { useGlobalPrefix: true });
const { httpAdapter } = app.get(HttpAdapterHost);
app.useGlobalFilters(
new AllExceptionsFilter(httpAdapter, app.get('NestWinston')),
);
// app.setGlobalPrefix('api', {
// exclude: ['swagger'],
// });
await app.init();
return app;
}
import { NestFactory, HttpAdapterHost } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
import helmet from 'helmet';
import * as fs from 'fs';
import { config, DotenvConfigOutput } from 'dotenv';
import { AllExceptionsFilter } from './base/all-exceptions.filter';
import * as databases from './config/databases';
import { BackendHandshakeDto } from './globals/dto/backend-handshake-dto';
import { HttpsOptions } from '@nestjs/common/interfaces/external/https-options.interface';
import { VersioningType } from '@nestjs/common';
async function bootstrap() {
// call dotenv-config to get .env values before nest app creation
const configuration: DotenvConfigOutput = config();
let httpsOptions: HttpsOptions = null;
const httpsPrivateKeyPath = configuration.parsed.HTTPS_KEY_PATH;
const httpsCertificatePath = configuration.parsed.HTTPS_CERT_PATH;
if (httpsPrivateKeyPath && httpsCertificatePath) {
httpsOptions = {
key: fs.readFileSync(httpsPrivateKeyPath),
cert: fs.readFileSync(httpsCertificatePath),
};
}
const handshake: BackendHandshakeDto = new BackendHandshakeDto();
const app = await NestFactory.create(AppModule, { httpsOptions });
app.use(helmet());
app.enableCors();
app.use((request, response, next) => {
response.header('Access-Control-Allow-Origin', '*');
response.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
response.header('Access-Control-Allow-Headers', 'Content-Type, Accept');
next();
});
app.enableVersioning({
defaultVersion: '1',
type: VersioningType.URI,
});
app.setGlobalPrefix('api');
const options = new DocumentBuilder()
.setTitle('TUNNEL:Manager API')
.setDescription(
`API for TUNNEL:Manager App
Supported database versions: ${databases.default.supportedVersions()}`,
)
.setVersion(handshake.backendVersion)
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, options, {
//ignoreGlobalPrefix: false,
});
SwaggerModule.setup('api-docs', app, document, { useGlobalPrefix: true });
const { httpAdapter } = app.get(HttpAdapterHost);
app.useGlobalFilters(
new AllExceptionsFilter(httpAdapter, app.get('NestWinston')),
);
await app.listen(process.env.SERVER_PORT || 3000);
}
bootstrap();
"dependencies": {
"@nestjs/azure-func-http": "^0.8.0",
"@nestjs/common": "^8.2.6",
"@nestjs/core": "^8.2.6",
"@nestjs/jwt": "^8.0.0",
"@nestjs/passport": "^8.1.0",
"@nestjs/platform-express": "^8.2.6",
"@nestjs/swagger": "^5.2.1",
"@nestjs/typeorm": "^8.0.3",
"cache-manager": "^3.6.0",
"co": "^4.6.0",
"compare-versions": "^3.6.0",
"helmet": "^5.0.2",
"js-sha512": "^0.8.0",
"markdown-it": "^12.3.2",
"mo": "^1.7.3",
"moment": "^2.29.1",
"mssql": "^6.4.0",
"nest-winston": "^1.6.2",
"nestjs-config": "^1.4.10",
"passport": "^0.5.2",
"passport-jwt": "^4.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.2",
"s": "^1.0.0",
"swagger-ui-express": "^4.3.0",
"typeorm": "^0.2.41",
"winston": "^3.5.1"
},
"devDependencies": {
"@azure/functions": "^1.2.3",
"@nestjs/testing": "^8.2.6",
"@types/express": "^4.17.13",
"@types/jest": "^23.3.13",
"@types/node": "12.12.43",
"@types/readable-stream": "2.3.5",
"@types/supertest": "^2.0.11",
"jest": "^27.4.7",
"nodemon": "^2.0.15",
"prettier": "^2.5.1",
"sqlite3": "^5.0.2",
"supertest": "^3.4.1",
"ts-jest": "^27.1.3",
"ts-node": "^10.4.0",
"tsconfig-paths": "^3.12.0",
"tslint": "6.1.3",
"typescript": "^4.5.5"
},
Would be nice if somebody can help us with this issue. I guess its a weird configuration issue.
Thank you anyway and bye
[ ] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Nest version: X.Y.Z
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Hi when I try to build my project using nest build
I get this error:
node_modules/@nestjs/azure-func-http/dist/router/azure-http.router.d.ts:4:22 -
error TS2515: Non-abstract class 'AzureHttpRouter' does not implement inherited abstract member 'getRequestHostname' from class 'AbstractHttpAdapter<any, any, any>'.
4 export declare class AzureHttpRouter extends AbstractHttpAdapter {
~~~~~~~~~~~~~~~
Found 1 error(s).
the code is basically:
// index.ts
import { Context, HttpRequest } from '@azure/functions';
import { AzureHttpAdapter } from '@nestjs/azure-func-http';
import { createApp } from '../src/main.azure';
export default function(context: Context, req: HttpRequest): void {
AzureHttpAdapter.handle(createApp, context, req);
}
// main.azure.ts
export async function createApp(): Promise<any> {
const app = await NestFactory.create(AppModule, new AzureHttpRouter());
}
I used to build ok, so I guess I had an old version installed, but I didn't see any other issues posted here so would love to know if its a bug or my configuration.
Can provide if required
Currently cannot build the project
Nest version: v10.18.0
For Tooling issues:
- Node version: v10.18.0
- Platform: macOs
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.
[ ] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
I've noticed that the peer dependencies are pinned to @azure/[email protected]^1.0.3
and @azure/[email protected]^3.0.0
but there's no support for @azure/[email protected]^2.0.0
.
As per the README of the @azure/functions
package addressing versioning, v1 of the package is in maintenance mode, v2 supports Azure Function runtime v3 which is not EOL, and v3 supports Azure Function Runtime v4 which is relatively new. Pinning this dependency to v1 or v3 leaves out a large majority of people who are still on Azure Functions runtime v3. If you're still supporting v1, which is in maintenance mode, there should be no reason that @azure/[email protected]^2.0.0
, still in general availability, isn't supported.
I propose a change to:
"peerDependencies": {
"@azure/functions": "^1.0.3 || ^2.0.0 || ^3.0.0",
...
},
[ ] Regression
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
No documentation surrounding use of azure context which is greatly needed for setting up logging for azure functions
Would love to see an example LoggerModule that can be used locally (default to console.log) or with azure func context (context.log)
Documentation surrounding this repository is very minimal, and outdated
[ ] Regression
[x] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Schematics fail. You need to install manually npm i @nestjs/azure-func-http
and then add schematics with nest add @nestjs/azure-func-http
.
Automatically install necessary dependencies.
nest add @nestjs/azure-func-http
Comodity
Nest version: 7.0.0
For Tooling issues:
- Node version: 12.18.3
- Platform: Linux
Others:
Thanks for your work,
[ ] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Nest version: X.Y.Z
For Tooling issues:
- Node version: XX
- Platform:
Others:
[ ] Regression
[v ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
npm start:azure
is not working
mpm start:dev
is well
We are testing Azure Function
we made Middleware and some url exclude
but it is not working
same issue reported
https://stackoverflow.com/questions/69198570/nestjs-middlewareconsumer-exclude-path-not-working-in-azure-function
Nest version: 8.0.0
For Tooling issues:
- Node version: 8.4.1
- Platform: Mac, Linux
Others:
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
When using this adapter and following this recipe: https://docs.nestjs.com/recipes/serve-static, the API crash when trying to serve a static file.
Static file serving works as intended.
curl
-> exceptionAllowing any regular use case valid for NestJS app.
Nest version: 6.12.2
For Tooling issues:
- Node version: 12.13.0
- Platform: Mac
Others:
[X] Feature request
[X] Documentation issue or request
The Azure Functions portal does not show any functions, it would be nice to have API routes here, for instance.
Have a decorator to mark controllers and methods or manually specify what should be defined, similar to how Swagger UI works.
[ ] Regression
[ ] Bug report
[ ] Feature request
[X] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
npm run build && func host start
Works fine! Thank You :-)
Installed, works fine! :-)
The function is started, the submitted post is received in the function, but no response is sent to the client.
This seems to be a configuration problem.
I will be happy if a sample app can be provided here or in nest/nest/sample.
Same feature requested by somebody, but no solution provided.
Details can be found here:
https://spectrum.chat/nestjs/help/unable-to-start-nestjs-graphql-azure-functions~4cc66b5d-69cd-4e36-a4f8-20006b1a2155
Nest version: 6.10.1
For Tooling issues:
- Node version: v10.17.0
- Platform: Windows 10
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.circleci/config.yml
cimg/node 19.6
cimg/node 19.6
package.json
cors 2.8.5
jsonc-parser ^3.2.0
trouter 3.2.0
@angular-devkit/schematics ^15.1.2
@azure/functions 3.5.0
@commitlint/cli 17.4.4
@commitlint/config-angular 17.4.4
@nestjs/common 9.3.10
@nestjs/core 9.3.10
@nestjs/schematics 9.0.4
@types/node 18.15.3
@types/jest 29.4.4
@typescript-eslint/eslint-plugin 5.55.0
@typescript-eslint/parser 5.55.0
@schematics/angular 15.2.3
eslint 8.36.0
eslint-config-prettier 8.7.0
eslint-plugin-import 2.27.5
husky 8.0.3
lint-staged 13.2.0
prettier 2.8.4
release-it 15.8.0
typescript 4.9.5
jest 29.5.0
ts-jest 29.0.5
@azure/functions ^1.0.3 || ^2.0.0 || ^3.0.0
@nestjs/common ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0
@nestjs/core ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0
reflect-metadata ^0.1.13
use nest js graphql app in an azure function
The function is started, the submitted post is received in the function, but no response is sent to the client.
[ ] Regression
[ X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
I am not sure if this is a bug, or a feature request.
git clone https://github.com/TrilonIO/nestjs-azure-functions
- the azure func demo app.npm install --save @nestjs/platform-fastify
npm install
the rest.npm run build && func host start
.func host start
has completed and the server is running.Fastify should have the same 200 success response as Express adaptor.
See instructions above.
I'd like to use Fastify with Azure functions as it's lighter weight and faster.
MacOS Catalina
NodeJS: 12.16.3
NestJS common, core: 7.0.8
NestJS platform-fastify 7.0.11
@nestjs/azure-func-http: 0.5.0
@azure/functions: 1.0.3
Others:
npm
VSCode
zsh
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
nest add @nestjs/azure-func-http
fails with the following messages
Failed to execute command: npm install --save @nestjs/[email protected]
Unable to install library @nestjs/azure-func-http because package did not install. Please check package name.
When I try npm install --save @nestjs/[email protected]
myself it gives more information. Viz
ERESOLVE unable to resolve dependency tree
While resolving: [email protected]
Found: @nestjs/[email protected]
node_modules/@nestjs/common
@nestjs/[email protected]"^9.0.0" from the root project
Could not resolve dependency:
peer @nestjs/[email protected]"^6.0.0 || ^7.0.0 || ^8.0.0" from @nestjs/[email protected]
node_modules/@nestjs/azure-func-http
@nestjs/[email protected]"0.8.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
The command should add the documented azure-func-http
capabilities
npm uninstall @nestjs/cli -g
npm install @nestjs/cli -g
nest n fapp
cd fapp
nest add @nestjs/azure-func-http
I am experimenting with an azure function for my api and wanted to use the features I read about with this plugin
Nest version: 9.0.0
For Tooling issues:
- Node version: 18.7.0
- Platform: Windows 11
Others:
npm: 8.16.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.