Skip to content

Commit

Permalink
add init func-app
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-ivanov committed Sep 17, 2018
1 parent 88e8265 commit dbe3810
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend-func-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
local.settings.json
35 changes: 35 additions & 0 deletions backend-func-app/HttpTriggerJS1/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "hello",
"methods": [
"get",
"post"
],
"authLevel": "anonymous"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "blob",
"name": "outputBlob",
"path": "output/{filename}",
"connection": "rocketleagueappfunc_STORAGE",
"direction": "out"
},
{
"type": "table",
"name": "outputTable",
"tableName": "submissions",
"connection": "rocketleagueappfunc_STORAGE",
"direction": "out"
}
],
"disabled": false
}
18 changes: 18 additions & 0 deletions backend-func-app/HttpTriggerJS1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.', context.bindings.outputBlob);

context.bindings.outputBlob = req.body;
if (req.query.name || (req.body && 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"
};
}
context.done();
};
20 changes: 20 additions & 0 deletions backend-func-app/HttpTriggerPython31/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post",
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"disabled": false
}
16 changes: 16 additions & 0 deletions backend-func-app/HttpTriggerPython31/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import json
from azure.storage.blob import BlockBlobService

response = open(os.environ['res'], 'w')

try:
#postreqdata = json.loads(open(os.environ['req']).read())
#os.environ['req']
name = "test" #os.environ['req_query_name']
response.write("hello world from "+name)
except ValueError as err:
print("Error " + err.message)

response.close()

35 changes: 35 additions & 0 deletions backend-func-app/UploadSubmission/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "upload",
"methods": [
"post",
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "table",
"name": "outputTable",
"tableName": "submissions",
"connection": "rocketleagueappfunc_STORAGE",
"direction": "out"
},
{
"type": "blob",
"name": "submissionBlob",
"path": "uploaded-submissions/{filename}",
"connection": "rocketleagueappfunc_STORAGE",
"direction": "out"
}
],
"disabled": false
}
55 changes: 55 additions & 0 deletions backend-func-app/UploadSubmission/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const azure = require('azure-storage');
const multer = require('multer');


module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
let storageConnection = GetEnvironmentVariable("rocketleagueappfunc_STORAGE");
context.log(storageConnection);
var blobService = azure.createBlobService(storageConnection);

blobService.listBlobsSegmented('uploaded-submissions', null, function(error, result, response){
context.log("blob list");
if(!error){
for(entryId in result.entries){
context.log("entry ", result.entries[entryId].name);
}
// result.entries contains the entries
// If not all blobs were returned, result.continuationToken has the continuation token.
}
});

// Iterates through trigger and input binding data
context.bindings.submissionBlob = req.body;
context.bindings.outputTable = [];
/*context.bindings.outputTable.push({
PartitionKey: "Test",
RowKey: "1234",
Name: "Name " + req.query.name,
Email: "test email 3"
});
*/
if (req.query.name || (req.body && 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"
};
}
outputBindings = {filename: "test.txt"};
context.log('output ',outputBindings);
context.log('body', req.body);
context.bindings.submissionBlob = req.body;

context.done(null, outputBindings );
};

function GetEnvironmentVariable(name)
{
return process.env[name];
}
1 change: 1 addition & 0 deletions backend-func-app/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
16 changes: 16 additions & 0 deletions backend-func-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "rocket_league_func_api",
"version": "1.0.0",
"description": "Rocket league funcitional app",
"productName": " Rocket League",
"author": "yuri.ivanov@capgemini.com",
"private": true,
"scripts": {},
"dependencies": {
"azure-storage": "^2.10.1"
},
"engines": {
"node": ">= 8.9.0",
"npm": ">= 5.6.0"
}
}
31 changes: 31 additions & 0 deletions backend-func-app/proxies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"home": {
"matchCondition": {
"route": "/",
"methods": [
"GET"
]
},
"backendUri": "https://rocketleagueappfunc.z16.web.core.windows.net/index.html"
},
"Static Assets": {
"matchCondition": {
"route": "/{*restOfPath}",
"methods": [
"GET",
"HEAD",
"OPTIONS"
]
},
"backendUri": "https://rocketleagueappfunc.z16.web.core.windows.net/{restOfPath}"
},
"api": {
"matchCondition": {
"route": "/api/{*url}"
},
"backendUri": "https://%WEBSITE_HOSTNAME%/api/{url}"
}
}
}

0 comments on commit dbe3810

Please sign in to comment.