Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#175072065] EXPERIMENTAL: Start io-backend as Azure Function #722

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

BurnedMarshal
Copy link
Contributor

No description provided.

@pagopa-github-bot
Copy link
Contributor

pagopa-github-bot commented Oct 20, 2020

Warnings
⚠️

Please include a description of your PR changes.

Affected stories

  • ⚙️ #175072065: Considerare il porting del backend su function serverless

New dependencies added: @azure/functions, io-functions-commons and @types/mime.

@azure/functions

Author: Microsoft

Description: Azure Functions types for Typescript

Homepage: http://npmjs.com/package/@azure/functions

Createdalmost 2 years ago
Last Updated5 months ago
LicenseMIT
Maintainers5
Releases7
Keywordsazure-functions and typescript
README

Type definitions for Azure Functions

This package contains type definitions for using TypeScript with Azure Functions.

These typings are for common objects that will be passed to your Azure Functions function code. Azure Functions supports TypeScript development, but does not support directly running TypeScript code without transpilation.

Read more on configuring entry points in your Azure Functions function app.

Install

Because this package only contains TypeScript type definitions, it should be saved under devDependencies.

npm install @azure/functions --save-dev

Usage

import { AzureFunction, Context, HttpRequest } from "@azure/functions";

const index: AzureFunction = async function (context: Context, req: HttpRequest) {
    context.log('JavaScript HTTP trigger function processed a request.');
    if (req.query.name || (req.body && req.body.name)) {
        context.res = {
            status: "200",
            body: "Hello " + (req.query.name || req.body.name)
        };
    } else {
        context.res = {
            status: 400,
            body: "Please pass a name on the query string or in the request body"
        };
    }
}

export { index };

Versions

Versioning of @azure/functions is tied to the version of the Azure Functions Node.js Worker the types were generated from. You can find the Azure Functions Node.js Worker version of a given Function Runtime Version here. It is recommended that you take the latest version available.

Getting Started with Azure Functions

If you are getting started with Azure Functions, you can follow this tutorial to create and deploy your first JavaScript function. We recommend that you use Visual Studio Code and the Azure Functions extension.

The Azure Functions developer guide and the JavaScript-specific developer guide are good resources to gain an understanding of more Azure Functions concepts.

io-functions-commons

Author: https://www.pagopa.gov.it

Description: Common code for Azure functions

Homepage: https://github.com/pagopa/io-functions-commons#readme

Createdover 1 year ago
Last Updated4 days ago
LicenseMIT
Maintainers4
Releases88
Direct Dependencies@azure/cosmos, applicationinsights, azure-storage, cidr-matcher, fp-ts, helmet, helmet-csp, io-functions-express, io-ts, italia-ts-commons, node-fetch, nodemailer, nodemailer-sendgrid, referrer-policy, rehype-stringify, remark-frontmatter, remark-parse, remark-rehype, request-ip, ulid, unified and winston
README

io-functions-commons

Common code across Azure functions of project IO.

To release a new package on GitHub and npm:

yarn release-it <minor|major|patch>

Upgrading from 13.x to 14.x

Version 14.x is the first version that uses italia-utils 5.x,
a major upgrade to the package that generates the provided Typescript definitions.

This translates in the fact that you must upgrade italia-utils to a version >= 5.x
if you want to upgrade your deps using io-functions-common 14.x.

@types/mime

Author: Unknown

Description: TypeScript definitions for mime

Homepage: http://npmjs.com/package/@types/mime

Createdover 4 years ago
Last Updatedabout 2 months ago
LicenseMIT
Maintainers1
Releases17
Direct Dependencies
README

Installation

npm install --save @types/mime

Summary

This package contains type definitions for mime (https://github.com/broofa/node-mime).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mime.

Additional Details

  • Last updated: Wed, 22 Jul 2020 18:12:53 GMT
  • Dependencies: none
  • Global values: mime, mimelite

Credits

These definitions were written by Jeff Goddard, and Daniel Hritzkiv.

Generated by 🚫 dangerJS

// Parse an urlencoded body.
app.use(bodyParser.urlencoded({ extended: true }));
// Parse an urlencoded body.
app.use(bodyParser.urlencoded({ extended: true }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does SPID login work without this?

src/app.ts Outdated

//
// Define the folder that contains the public assets.
//

app.use(express.static("public"));
app.get(/(\.html|\.svg|\.png)$/, async (req, res, next) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the result of this call can be cached using appcache, what about this?

src/app.ts Outdated
Comment on lines 269 to 293
try {
const path = "public" + req.path;
if (!fs.existsSync(path)) {
return next();
}
const stat = await fs.promises.stat(path);
if (stat.isDirectory()) {
return next();
}
const type = mime.lookup(path);
if (type) {
const charset = mime.charsets.lookup(type);
res.setHeader(
"Content-Type",
// tslint:disable-next-line: restrict-plus-operands
type + (charset ? `; charset=${charset}` : "")
);
}
const content = await fs.promises.readFile(path);
res.setHeader("Content-Length", stat.size);
res.status(200).send(content);
} catch (err) {
log.error(`static|Error retrieving static file asset|error:%s`, err);
return next(err);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why we introduced this behaviour. Besides that, we can put this in a middleware function (req, res, next)=>void and we can give this chunk an explicit meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is required because the express default static folder (ref) doesn't work inside Azure functions. Here we emulate what static middleware does. We can create a specific middleware, but this code will be used only on this endpoint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can just move it in a function declared inside the same module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 94282ce

src/config.ts Outdated Show resolved Hide resolved
@@ -175,7 +173,7 @@ describe("SessionLockController#unlockUserSession", () => {
mockRedisUserMetadataStorage
);

const response = await controller.lockUserSession(req);
const response = await controller.unlockUserSession(req);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

balanza and others added 24 commits October 21, 2020 10:38
* update spid-commons

* revert typo

* update spid-commons
* [#175679733] Add GetSupportToken API

* [#175679733] Add tests + minor refactoring

* [#175679733] env.example update

* [#175679733] Refactor over review

* [#175679733] Minor refactor over review

* [#175679733] Fix tests

* [#175679733] Remove useless attribute

* [#175679733] Minor refactor over review

* [#175679733] refactor env variable decoding

* [#175679733] Fix tests
* [#176003320] Return 500 instead of 401 on system errors

* Fix done param

Co-authored-by: danilo spinelli <danilo.spinelli@pagopa.itt>
Co-authored-by: pasqualedevita <>
Co-authored-by: pasqualedevita <>
Co-authored-by: pasqualedevita <>
@codecov
Copy link

codecov bot commented Dec 5, 2020

Codecov Report

Merging #722 (94282ce) into master (7e1db7b) will decrease coverage by 0.54%.
The diff coverage is 35.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #722      +/-   ##
==========================================
- Coverage   79.67%   79.13%   -0.55%     
==========================================
  Files          68       68              
  Lines        2298     2320      +22     
  Branches      375      375              
==========================================
+ Hits         1831     1836       +5     
- Misses        454      471      +17     
  Partials       13       13              
Impacted Files Coverage Δ
src/server.ts 0.00% <ø> (ø)
src/app.ts 88.46% <28.00%> (-7.30%) ⬇️
src/controllers/authenticationController.ts 95.09% <100.00%> (ø)
src/types/user.ts 89.33% <100.00%> (ø)
src/controllers/sessionLockController.ts 100.00% <0.00%> (+3.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0fa3c70...d7312f2. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants