-
Notifications
You must be signed in to change notification settings - Fork 19
Use an app
root object for all function registrations
#12
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
Comments
More feedback from offline:
|
We modeled const express = require('express')
const app = express() // technically I could name this anything In regards to the second bullet point, users can already do this, which may be easier than the above workaround: const func = require(‘@azure/functions’);
func.app. |
I do question this statement a bit:
Yes, it's true that const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
}) We could have a porting story that allows you to write: const app = require('@azure/functions-express')
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
}) And there's no other changes needed in the codebase, the |
Let me elaborate on the const { app } = require("@azure/functions"); If we are going to advocate for the destructured export in our docs, then I'd recommend giving the user the option (in the docs) where they can rename this export: const { app: myFunc } = require("@azure/functions");
// or esm imports version?
// import { app: myFunc } from "@azure/functions";
myFunc.get('/', (req, res) => {
res.send('Hello World!')
}) With that being said, if users decide to ignore named export, then I agree that it's their responsibility to follow whatever naming convention they are using: import myFunc from"@azure/functions";
myFunc.app.get('/', (req, res) => {
res.send('Hello World!')
}) |
I second this. This is the expectation right now for anyone using languages services and a default when writing other type of components (resources), even via IaC. |
My initial thinking was "that can be mitigated with aliases" and I am not sure I can see the collision with frontend libraries being a very frequent scenario, but I do agree that we must document the migration path and portability support from express, with code samples, and perhaps a parity matrix when popular methods with the same name are part of the exported Basically, we need to make sure a portability path is guided and what's possible and what's not, is made very clear. |
Some other offline feedback on this: Another suggestion would essentially flip the hierarchy of namespaces from import { sb, storage, http, HttpResponse } from `@azure/functions`
const blobInput = storage.input.blob(/* blob options */);
const queueOutput = storage.output.queue(/* queue options */);
const httpOutput = http.output(/* HTTP options */);
sb.app.topic({
// SB options
return: httpOutput,
extraInputs: [blobInput],
extraOutputs: [queueOutput],
handler: async function (message: unknown, context: InvocationContext): Promise<HttpResponse> {
// read blob input
const blobValue = storage.blob.getBlob(context, blobInput);
// set queue output
storage.queue.setMessage(context, queueOutput, `Hello, ${message}`);
// return value mapped to http output
return new HttpResponse({ response: 200 });
}
}); I think this suggestion was made mainly because durable exports its own functions under its own |
Closing as the current design can be considered final since we recently GA'ed. |
Copied from ejizba/func-nodejs-prototype#3
Collecting feedback from various places on the
app
root object. Seems like everyone is overwhelmingly in favor of it, but we can have further discussion here.From @aaronpowell:
From @YunchuWang
The text was updated successfully, but these errors were encountered: