Skip to content
Open
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
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node Functions",
"type": "node",
"request": "attach",
"port": 9229,
"preLaunchTask": "func: host start"
}
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"azureFunctions.deploySubpath": "api",
"azureFunctions.postDeployTask": "npm install (functions)",
"azureFunctions.projectLanguage": "TypeScript",
"azureFunctions.projectRuntime": "~3",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.preDeployTask": "npm prune (functions)"
}
43 changes: 43 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"command": "host start",
"problemMatcher": "$func-node-watch",
"isBackground": true,
"dependsOn": "npm build (functions)",
"options": {
"cwd": "${workspaceFolder}/api"
}
},
{
"type": "shell",
"label": "npm build (functions)",
"command": "npm run build",
"dependsOn": "npm install (functions)",
"problemMatcher": "$tsc",
"options": {
"cwd": "${workspaceFolder}/api"
}
},
{
"type": "shell",
"label": "npm install (functions)",
"command": "npm install",
"options": {
"cwd": "${workspaceFolder}/api"
}
},
{
"type": "shell",
"label": "npm prune (functions)",
"command": "npm prune --production",
"dependsOn": "npm build (functions)",
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}/api"
}
}
]
}
6 changes: 6 additions & 0 deletions api/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.js.map
*.ts
.git*
.vscode
local.settings.json
test
43 changes: 43 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
bin
obj
csx
.vs
edge
Publish

*.user
*.suo
*.cscfg
*.Cache
project.lock.json

/packages
/TestResults

/tools/NuGet.exe
/App_Data
/secrets
/data
.secrets
appsettings.json
local.settings.json

node_modules
dist

# Local python packages
.python_packages/

# Python Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
5 changes: 5 additions & 0 deletions api/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}
20 changes: 20 additions & 0 deletions api/GetUserInfo/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/GetUserInfo/index.js"
}
54 changes: 54 additions & 0 deletions api/GetUserInfo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions"
import { CosmosClient, Database, Container } from '@azure/cosmos';

interface IUser {
username: string;
groupID: string;
numberOfPets: number,
id: string
}

const endpoint = process.env.DB_ENDPOINT;
const key = process.env.DB_KEY;
const databaseName = process.env.DB_ID;
const collection = process.env.COLLECTION;

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
context.log('Get User Info is running.');

const client = new CosmosClient({ endpoint, key });

const database = client.database(databaseName);
const container = database.container(collection);

const query = `SELECT * FROM c WHERE c.groupID = "123456"`;
const groupRes = await container.items.query(query).fetchAll();

let itemRes = await container.item('121212', '123456').read<IUser>();

context.log(`He'res Item Res:`, itemRes);


if (groupRes.resources.length === 0) {
context.res = {
status: 404,
body: {
code: 404,
message: 'no items found.'
}
}
context.done();
return;
}

context.res = {
// status: 200, /* Defaults to 200 */
body: {
items: groupRes.resources,
item: itemRes.resource
}
};

};

export default httpTrigger;
20 changes: 20 additions & 0 deletions api/HelloNew/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/HelloNew/index.js"
}
17 changes: 17 additions & 0 deletions api/HelloNew/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 = name
? "Hello, " + name + ". This HTTP triggered function executed successfully."
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";

context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};

};

export default httpTrigger;
20 changes: 20 additions & 0 deletions api/HelloWorld/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/HelloWorld/index.js"
}
32 changes: 32 additions & 0 deletions api/HelloWorld/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 header = req.headers['x-ms-client-principal'];

let clientPrincipal = null;

if (header) {
const encoded = Buffer.from(header, 'base64');
const decoded = encoded.toString('ascii');

clientPrincipal = JSON.parse(decoded);
}

const secretName = process.env.SECRET_NAME;

const name = (req.query.name || (req.body && req.body.name) || secretName);
const responseMessage = name
? "Hello, " + name + ". This HTTP triggered function executed successfully."
: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";

context.res = {
// status: 200, /* Defaults to 200 */
body: { responseMessage, clientPrincipal }
};

};

export default httpTrigger;
15 changes: 15 additions & 0 deletions api/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
Loading