Skip to content

Commit

Permalink
[3.0.0-alpha.0] First try to upgrade to Programming Model V4
Browse files Browse the repository at this point in the history
  • Loading branch information
maaaNu committed Apr 9, 2024
1 parent 312ce8c commit 41cb3f1
Show file tree
Hide file tree
Showing 30 changed files with 908 additions and 603 deletions.
10 changes: 10 additions & 0 deletions example/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.js.map
*.ts
.git*
.vscode
__azurite_db*__.json
__blobstorage__
__queuestorage__
local.settings.json
test
tsconfig.json
2 changes: 1 addition & 1 deletion example/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
"version": "[4.*, 5.0.0)"
}
}
82 changes: 75 additions & 7 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "1.0.0",
"description": "Test project to demonstrate the azure-function-middleware",
"scripts": {
"test": "jest",
"build": "tsc",
"start:host": "func start --port 8080 --javascript",
"start": "npm-run-all --parallel start:host watch",
"watch": "tsc --w"
"watch": "tsc -w",
"clean": "rimraf dist",
"prestart": "npm run clean && npm run build",
"start": "func start"
},
"keywords": [
"azure",
Expand All @@ -25,8 +25,9 @@
"typescript": "^4.4.3"
},
"dependencies": {
"@azure/functions": "^3.0.0",
"@azure/functions": "^4.2.0",
"@types/node": "^18.11.18",
"joi": "^17.9.1"
}
},
"main": "dist/example/src/*.js"
}
17 changes: 17 additions & 0 deletions example/src/invocationHook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PostInvocationContext, PreInvocationContext, app } from '@azure/functions';

app.hook.preInvocation((context: PreInvocationContext) => {
if (context.invocationContext.options.trigger.type === 'httpTrigger') {
context.invocationContext.log(
`preInvocation hook executed for http function ${context.invocationContext.functionName}`,
);
}
});

app.hook.postInvocation((context: PostInvocationContext) => {
if (context.invocationContext.options.trigger.type === 'httpTrigger') {
context.invocationContext.log(
`postInvocation hook executed for http function ${context.invocationContext.functionName}`,
);
}
});
15 changes: 15 additions & 0 deletions example/src/test-header-authentication-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HttpRequest, InvocationContext, app } from '@azure/functions';

import { middleware } from '../../src';
import headerAuthentication from '../../src/headerAuthentication';

export const handler = async (request: HttpRequest, context: InvocationContext) => {
context.info('Function called');
return { status: 204 };
};
app.http('test-header-authentication-function', {
methods: ['POST'],
authLevel: 'anonymous',
route: 'authentication',
handler: middleware([headerAuthentication()], handler, []),
});
27 changes: 27 additions & 0 deletions example/src/test-jwt-authorization-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { HttpHandler, HttpRequestParams, app } from '@azure/functions';

import { middleware } from '../../src';
import authorization from '../../src/jwtAuthorization';

export const handler: HttpHandler = async (req, context) => {
context.log('Function called');
return { status: 204 };
};

app.http('test-jwt-authorization-function', {
methods: ['POST'],
authLevel: 'anonymous',
route: 'authorization/{id}',
handler: middleware<HttpHandler>(
[
authorization([
{
parameterExtractor: (parameters: HttpRequestParams) => parameters.id,
jwtExtractor: (jwt: { userId: string }) => jwt.userId,
},
]),
],
handler,
[],
),
});
29 changes: 29 additions & 0 deletions example/src/test-validation-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { HttpHandler, app } from '@azure/functions';
import * as Joi from 'joi';
import { ObjectSchema } from 'joi';

import { PostExecutionFunction, middleware } from '../../src';
import { requestValidation as validation } from '../../src/validation';

const schema: ObjectSchema = Joi.object({
name: Joi.string().min(3).max(30).required(),
}).required();

export const functionHandler: HttpHandler = async (req, context) => {
context.info('Function called');
const body = (await req.json()) as { name: string };

return { status: 200, jsonBody: { text: `Hallo ${body.name}` } };
};

const postFunction: PostExecutionFunction = (_, context) => {
context.log('Called after function');
return;
};

app.http('test-validation-function', {
methods: ['POST'],
authLevel: 'anonymous',
route: 'validation',
handler: middleware<HttpHandler>([validation(schema, { printRequest: true })], functionHandler, [postFunction]),
});
19 changes: 0 additions & 19 deletions example/test-header-authentication-function/function.json

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions example/test-jwt-authorization-function/function.json

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions example/test-validation-function/function.json

This file was deleted.

Loading

0 comments on commit 41cb3f1

Please sign in to comment.