From a8edcfe123ece895b4a96f380a2645256eeb069e Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Fri, 28 May 2021 01:31:18 +0200 Subject: [PATCH] Starting to work with functions --- api/.funcignore | 7 +++ api/.gitignore | 94 +++++++++++++++++++++++++++++++++++++++ api/host.json | 15 +++++++ api/package-lock.json | 20 +++++++++ api/package.json | 17 +++++++ api/profile/function.json | 20 +++++++++ api/profile/index.ts | 15 +++++++ api/profile/sample.dat | 3 ++ api/proxies.json | 4 ++ api/tsconfig.json | 10 +++++ package-lock.json | 13 ++++++ staticwebapp.config.json | 12 +++++ 12 files changed, 230 insertions(+) create mode 100644 api/.funcignore create mode 100644 api/.gitignore create mode 100644 api/host.json create mode 100644 api/package-lock.json create mode 100644 api/package.json create mode 100644 api/profile/function.json create mode 100644 api/profile/index.ts create mode 100644 api/profile/sample.dat create mode 100644 api/proxies.json create mode 100644 api/tsconfig.json create mode 100644 staticwebapp.config.json diff --git a/api/.funcignore b/api/.funcignore new file mode 100644 index 0000000..5179222 --- /dev/null +++ b/api/.funcignore @@ -0,0 +1,7 @@ +*.js.map +*.ts +.git* +.vscode +local.settings.json +test +tsconfig.json \ No newline at end of file diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..772851c --- /dev/null +++ b/api/.gitignore @@ -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 \ No newline at end of file diff --git a/api/host.json b/api/host.json new file mode 100644 index 0000000..6ab6643 --- /dev/null +++ b/api/host.json @@ -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)" + } +} diff --git a/api/package-lock.json b/api/package-lock.json new file mode 100644 index 0000000..7674d94 --- /dev/null +++ b/api/package-lock.json @@ -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 + } + } +} diff --git a/api/package.json b/api/package.json new file mode 100644 index 0000000..b5e6d28 --- /dev/null +++ b/api/package.json @@ -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" + } +} diff --git a/api/profile/function.json b/api/profile/function.json new file mode 100644 index 0000000..4679313 --- /dev/null +++ b/api/profile/function.json @@ -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" +} diff --git a/api/profile/index.ts b/api/profile/index.ts new file mode 100644 index 0000000..3835351 --- /dev/null +++ b/api/profile/index.ts @@ -0,0 +1,15 @@ +import { AzureFunction, Context, HttpRequest } from "@azure/functions" + +const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise { + 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; \ No newline at end of file diff --git a/api/profile/sample.dat b/api/profile/sample.dat new file mode 100644 index 0000000..26aac46 --- /dev/null +++ b/api/profile/sample.dat @@ -0,0 +1,3 @@ +{ + "name": "Azure" +} \ No newline at end of file diff --git a/api/proxies.json b/api/proxies.json new file mode 100644 index 0000000..b385252 --- /dev/null +++ b/api/proxies.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/proxies", + "proxies": {} +} diff --git a/api/tsconfig.json b/api/tsconfig.json new file mode 100644 index 0000000..77d91aa --- /dev/null +++ b/api/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "outDir": "dist", + "rootDir": ".", + "sourceMap": true, + "strict": false + } +} diff --git a/package-lock.json b/package-lock.json index 072a743..f988b9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/staticwebapp.config.json b/staticwebapp.config.json new file mode 100644 index 0000000..9f161bd --- /dev/null +++ b/staticwebapp.config.json @@ -0,0 +1,12 @@ +{ + "routes": [ + { + "route": "/profile", + "allowedRoles": ["authenticated"] + }, + { + "route": "/admin/*", + "allowedRoles": ["administrator"] + } + ] +} \ No newline at end of file