Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/plugins/create/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const validTemplates = [
'tencent-python',
'tencent-php',
'azure-nodejs',
'azure-nodejs-typescript',
'azure-python',
'cloudflare-workers',
'cloudflare-workers-enterprise',
Expand Down
20 changes: 20 additions & 0 deletions lib/plugins/create/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,26 @@ describe('Create', () => {
});
});

it('should generate scaffolding for "azure-nodejs-typescript" template', () => {
process.chdir(tmpDir);
create.options.template = 'azure-nodejs-typescript';

return create.create().then(() => {
const dirContent = fs.readdirSync(tmpDir);
expect(dirContent).to.include('package.json');
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('.gitignore');
expect(dirContent).to.include('host.json');
expect(dirContent).to.include('README.md');
expect(dirContent).to.include('tsconfig.json');
expect(dirContent).to.include('webpack.config.js');

const srcContent = fs.readdirSync('src/handlers');
expect(srcContent).to.include('hello.ts');
expect(srcContent).to.include('goodbye.ts');
});
});

it('should generate scaffolding for "azure-python" template', () => {
process.chdir(tmpDir);
create.options.template = 'azure-python';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Azure Functions

Refer to [Serverless docs](https://serverless.com/framework/docs/providers/azure/guide/intro/) for more information.
94 changes: 94 additions & 0 deletions lib/plugins/create/templates/azure-nodejs-typescript/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TypeScript output
dist
out

# Azure Functions artifacts
bin
obj
appsettings.json
local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.0"
}
25 changes: 25 additions & 0 deletions lib/plugins/create/templates/azure-nodejs-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "azure-nodejs-typescript",
"version": "1.0.0",
"description": "Azure Functions webpack sample for the Serverless framework using Typescript",
"scripts": {
"test": "echo \"No tests yet...\"",
"start": "func host start"
},
"keywords": [
"azure",
"serverless"
],
"dependencies": {},
"devDependencies": {
"@azure/functions": "^1.0.3",
"@types/node": "^13.1.8",
"fork-ts-checker-webpack-plugin": "^3.0.1",
"serverless-azure-functions": "^1.0.0",
"serverless-webpack": "^5.3.1",
"ts-loader": "^6.2.1",
"typescript": "^3.7.5",
"webpack": "^4.41.5",
"webpack-node-externals": "^1.7.2"
}
}
135 changes: 135 additions & 0 deletions lib/plugins/create/templates/azure-nodejs-typescript/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!

service: azure-nodejs-typescript # NOTE: update this with your service name

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true

provider:
name: azure
region: West US 2
runtime: nodejs12.x
# prefix: "sample" # prefix of generated resource name
# subscriptionId: A356AC8C-E310-44F4-BF85-C7F29044AF99
# stage: dev
# type: premium # premium azure functions

environment: # these will be created as application settings
VARIABLE_FOO: 'foo'

# you can define apim configuration here
# apim:
# apis:
# - name: v1
# subscriptionRequired: false # if true must provide an api key
# displayName: v1
# description: V1 sample app APIs
# protocols:
# - https
# path: v1
# tags:
# - tag1
# - tag2
# authorization: none
# cors:
# allowCredentials: false
# allowedOrigins:
# - "*"
# allowedMethods:
# - GET
# - POST
# - PUT
# - DELETE
# - PATCH
# allowedHeaders:
# - "*"
# exposeHeaders:
# - "*"

plugins: # look for additional plugins in the community plugins repo: https://github.com/serverless/plugins
- serverless-azure-functions
- serverless-webpack

functions:
hello:
handler: src/handlers/hello.sayHello
events:
- http: true
x-azure-settings:
methods:
- GET
authLevel: anonymous # can also be `function` or `admin`

goodbye:
handler: src/handlers/goodbye.sayGoodbye
events:
- http: true
x-azure-settings:
methods:
- GET
authLevel: anonymous
# The following are a few examples of other events you can configure:
# storageBlob:
# handler: src/handlers/storageBlob.printMessage
# events:
# - blob:
# x-azure-settings:
# name: blob # Specifies which name is available on `context`
# path: blob-sample/{blobName}
# connection: AzureWebJobsStorage # App Setting/environment variable which contains Storage Account Connection String
# storageQueue:
# handler: src/handlers/storageQueue.printMessage
# events:
# - queue: queue-sample
# x-azure-settings:
# name: message # Specifies which naem is available on `context`
# connection: AzureWebJobsStorage
# timer:
# handler: src/handlers/timer.printMessage
# events:
# - timer:
# x-azure-settings:
# schedule: '*/10 * * * * *'
# eventhub:
# handler: src/handlers/eventHub.printMessage
# events:
# - eventHub:
# x-azure-settings:
# name: eventHubMessages # Specifies which name it's available on `context`
# eventHubName: sample-hub # Specifies the Name of the Event Hub
# consumerGroup: $Default # Specifies the consumerGroup to listen with
# connection: EVENT_HUBS_CONNECTION # App Setting/environment variable which contains Event Hubs Namespace Connection String
# serviceBusQueue:
# handler: src/handlers/serviceBusQueue.printMessage
# events:
# - serviceBus:
# x-azure-settings:
# name: message # Specifies which name is available on `context`
# queueName: sample-queue # Name of the service bus queue to consume
# connection: SERVICE_BUS_CONNECTION # App Setting/environment variable variable which contains Service Bus Namespace Connection String
# serviceBusTopic:
# handler: src/handlers/serviceBusTopic.printMessage
# events:
# - serviceBus:
# x-azure-settings:
# name: message # Specifies which name it's available on `context`
# topicName: sample-topic # Name of the service bus topic to consume
# subscriptionName: sample-subscription # Name of the topic subscription to retrieve from
# connection: SERVICE_BUS_CONNECTION # App Setting/environment variable variable which contains Service Bus Namespace Connection String
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AzureFunction, Context, HttpRequest } from '@azure/functions';

const sayGoodbye: AzureFunction = async function (context: Context, req: HttpRequest) {
context.log('Typescript HTTP trigger function processed a request.');

if (req.query.name || (req.body?.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
body: `Goodbye ${(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',
};
}
};

module.exports.sayGoodbye = sayGoodbye;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AzureFunction, Context, HttpRequest } from '@azure/functions';

const sayHello: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
context.log('Typescript HTTP trigger function processed a request.');

if (req.query.name || (req.body?.name)) {
context.res = {
// status: 200, /* Defaults to 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'
};
}
}

module.exports.sayHello = sayHello;
20 changes: 20 additions & 0 deletions lib/plugins/create/templates/azure-nodejs-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"lib": ["es2017"],
"removeComments": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
"target": "es2017",
"outDir": "lib"
},
"include": ["./**/*.ts"],
"exclude": [
"node_modules/**/*",
".serverless/**/*",
".webpack/**/*",
"_warmup/**/*",
".vscode/**/*"
]
}
Loading