Starting to work with functions

This commit is contained in:
Julien Lengrand-Lambert
2021-05-28 01:31:18 +02:00
parent 32e7a48407
commit a8edcfe123
12 changed files with 230 additions and 0 deletions

7
api/.funcignore Normal file
View File

@@ -0,0 +1,7 @@
*.js.map
*.ts
.git*
.vscode
local.settings.json
test
tsconfig.json

94
api/.gitignore vendored Normal file
View File

@@ -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

15
api/host.json Normal file
View File

@@ -0,0 +1,15 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}

20
api/package-lock.json generated Normal file
View File

@@ -0,0 +1,20 @@
{
"name": "api",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@azure/functions": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@azure/functions/-/functions-1.2.3.tgz",
"integrity": "sha512-dZITbYPNg6ay6ngcCOjRUh1wDhlFITS0zIkqplyH5KfKEAVPooaoaye5mUFnR+WP9WdGRjlNXyl/y2tgWKHcRg==",
"dev": true
},
"typescript": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.2.tgz",
"integrity": "sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==",
"dev": true
}
}
}

17
api/package.json Normal file
View File

@@ -0,0 +1,17 @@
{
"name": "api",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"prestart": "npm run build",
"start": "func start",
"test": "echo \"No tests yet...\""
},
"dependencies": {},
"devDependencies": {
"@azure/functions": "^1.2.3",
"typescript": "^4.0.0"
}
}

20
api/profile/function.json Normal file
View File

@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/profile/index.js"
}

15
api/profile/index.ts Normal file
View File

@@ -0,0 +1,15 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions"
const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
context.log('HTTP trigger function processed a request.');
const name = (req.query.name || (req.body && req.body.name));
const responseMessage = "profile location";
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
};
export default httpTrigger;

3
api/profile/sample.dat Normal file
View File

@@ -0,0 +1,3 @@
{
"name": "Azure"
}

4
api/proxies.json Normal file
View File

@@ -0,0 +1,4 @@
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {}
}

10
api/tsconfig.json Normal file
View File

@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"strict": false
}
}

13
package-lock.json generated
View File

@@ -13,6 +13,7 @@
"lit": "*"
},
"devDependencies": {
"@azure/functions": "^1.2.3",
"@open-wc/building-rollup": "^1.10.0",
"@open-wc/eslint-config": "^4.3.0",
"@open-wc/testing": "^2.5.33",
@@ -34,6 +35,12 @@
"typescript": "^4.2.4"
}
},
"node_modules/@azure/functions": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@azure/functions/-/functions-1.2.3.tgz",
"integrity": "sha512-dZITbYPNg6ay6ngcCOjRUh1wDhlFITS0zIkqplyH5KfKEAVPooaoaye5mUFnR+WP9WdGRjlNXyl/y2tgWKHcRg==",
"dev": true
},
"node_modules/@babel/code-frame": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz",
@@ -11589,6 +11596,12 @@
}
},
"dependencies": {
"@azure/functions": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@azure/functions/-/functions-1.2.3.tgz",
"integrity": "sha512-dZITbYPNg6ay6ngcCOjRUh1wDhlFITS0zIkqplyH5KfKEAVPooaoaye5mUFnR+WP9WdGRjlNXyl/y2tgWKHcRg==",
"dev": true
},
"@babel/code-frame": {
"version": "7.12.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.13.tgz",

12
staticwebapp.config.json Normal file
View File

@@ -0,0 +1,12 @@
{
"routes": [
{
"route": "/profile",
"allowedRoles": ["authenticated"]
},
{
"route": "/admin/*",
"allowedRoles": ["administrator"]
}
]
}