-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Added azure-node-http example 🎉 #98
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
functions | ||
.serverless | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Simple HTTP example | ||
|
||
In this example, we deploy an HTTP Node.js Azure Function. This sample show you how to read properties off of a query string or the request body, then set a result back to Azure. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "This sample shows ..., then sets ..." |
||
|
||
See the [Azure Functions Serverless Plugin docs](https://www.serverless.com/framework/docs/providers/azure/) for more info. | ||
|
||
## Setup | ||
|
||
1. We recommend Node.js v6.5.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is given by Azure, not really something the user can choose. |
||
2. Install the serverless framework - `npm i -g serverless` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be assumed to be installed. |
||
3. Install the dependencies of this example - `npm i` | ||
|
||
## Deploying | ||
|
||
To deploy, set up your [Credentials](https://www.serverless.com/framework/docs/providers/azure/guide/credentials) and run | ||
|
||
```bash | ||
serverless deploy | ||
``` | ||
|
||
## Invoking | ||
|
||
Once deployed, run | ||
|
||
```bash | ||
serverless invoke -f hello | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
module.exports.hello = (context, req) => { | ||
context.log('JavaScript HTTP trigger function processed a request.'); | ||
const res = {}; | ||
if (req.query.name || (req.body && req.body.name)) { | ||
// status: 200, /* Defaults to 200 */ | ||
const name = req.query.name || req.body.name; | ||
res.body = `Hello ${name}`; | ||
} else { | ||
res.status = 400; | ||
res.body = 'Please pass a name on the query string or in the request body'; | ||
} | ||
context.done(null, res); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "azure-node-simple-http-endpoint", | ||
"version": "0.1.0", | ||
"description": "An example of making http endpoints with the Azure Functions Serverless Framework plugin", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "serverless.com", | ||
"license": "MIT", | ||
"dependencies": { | ||
"serverless-azure-functions": "^0.1.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
service: azfx-node-http | ||
|
||
provider: | ||
name: azure | ||
azureSubId: YourAzureSubscriptionID | ||
azureServicePrincipalTenantId: servicePrincipalTenantId | ||
azureservicePrincipalClientId: servicePrincipalClientId | ||
azureServicePrincipalPassword: servicePrincipalPassword | ||
location: West US | ||
|
||
plugins: | ||
- serverless-azure-functions | ||
|
||
package: | ||
exclude: | ||
- node_modules/** | ||
- .gitignore | ||
- package.json | ||
- .git/** | ||
|
||
functions: | ||
hello: | ||
handler: handler.hello | ||
events: | ||
- http: true | ||
x-azure-settings: | ||
authLevel : anonymous | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider configuring your editor to add a newline at the end of the file (or simply remove the trailing spaces after the last newline). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider configuring your editor to add a newline at the end of the file.