This repository has been archived by the owner on Apr 8, 2022. It is now read-only.
forked from simonaco/pbp-serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 15fe67e
Showing
17 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
bin | ||
obj | ||
csx | ||
.vs | ||
edge | ||
Publish | ||
.vscode | ||
|
||
*.user | ||
*.suo | ||
*.cscfg | ||
*.Cache | ||
project.lock.json | ||
|
||
/packages | ||
/TestResults | ||
|
||
/tools/NuGet.exe | ||
/App_Data | ||
/secrets | ||
/data | ||
.secrets | ||
appsettings.json | ||
local.settings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"disabled": false, | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"route": "hero", | ||
"methods": ["post"] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const MongoClient = require('mongodb').MongoClient; | ||
const auth = require('../shared/index'); | ||
module.exports = function(context, req) { | ||
MongoClient.connect( | ||
process.env.CosmosDBURL, | ||
{ auth: auth }, | ||
(err, database) => { | ||
if (err) throw err; | ||
let hero = ({ id, name, saying } = req.body); | ||
var db = database.db('admin'); | ||
|
||
db.collection('Heroes').insertOne( | ||
{ | ||
id: hero.id, | ||
name: hero.name, | ||
saying: hero.saying | ||
}, | ||
(err, result) => { | ||
if (err) throw err; | ||
context.res = { | ||
body: hero | ||
}; | ||
database.close(); | ||
context.done(); | ||
} | ||
); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "Azure" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"disabled": false, | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"route": "hero/{id}", | ||
"methods": ["delete"] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const MongoClient = require('mongodb').MongoClient; | ||
const auth = require('../shared/index'); | ||
module.exports = function(context, req) { | ||
context.log('JavaScript HTTP trigger function processed a request.'); | ||
MongoClient.connect( | ||
process.env.CosmosDBURL, | ||
{ auth: auth }, | ||
(err, database) => { | ||
if (err) throw err; | ||
const db = database.db('admin'); | ||
let heroId = req.params.id; | ||
db | ||
.collection('Heroes') | ||
.findOneAndDelete({ id: heroId }, (err, result) => { | ||
if (err) throw err; | ||
context.res = { | ||
status: 200, | ||
body: { message: 'Hero deleted successfully!' } | ||
}; | ||
database.close(); | ||
context.done(); | ||
}); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "Azure" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"disabled": false, | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"route": "heroes", | ||
"methods": ["get"] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const MongoClient = require('mongodb').MongoClient; | ||
const auth = require('../shared/index'); | ||
module.exports = function(context, req) { | ||
context.log('JavaScript HTTP trigger function processed a request.'); | ||
MongoClient.connect( | ||
process.env.CosmosDBURL, | ||
{ auth: auth }, | ||
(err, database) => { | ||
if (err) throw err; | ||
console.log('Connected succesfully'); | ||
const db = database.db(process.env.CosmosDB); | ||
db | ||
.collection('Heroes') | ||
.find() | ||
.toArray((err, result) => { | ||
if (err) throw err; | ||
console.log('retrieved succesfully'); | ||
result.forEach(hero => delete hero._id); | ||
context.res = { | ||
//status: 200, | ||
body: result | ||
}; | ||
database.close(); | ||
context.done(); | ||
}); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "Azure" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"disabled": false, | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"route": "hero/{id}", | ||
"methods": ["put"] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const MongoClient = require('mongodb').MongoClient; | ||
const auth = require('../shared/index'); | ||
module.exports = function(context, req) { | ||
context.log('JavaScript HTTP trigger function processed a request.'); | ||
MongoClient.connect( | ||
process.env.CosmosDBURL, | ||
{ auth: auth }, | ||
(err, database) => { | ||
if (err) throw err; | ||
const db = database.db('admin'); | ||
let hero = ({ id, name, saying } = req.body); | ||
let heroId = req.params.id; | ||
db | ||
.collection('Heroes') | ||
.findOneAndUpdate( | ||
{ id: heroId }, | ||
{ $set: { id: hero.id, name: hero.name, saying: hero.saying } }, | ||
(err, heroes) => { | ||
if (err) throw err; | ||
context.res = { | ||
body: hero | ||
}; | ||
database.close(); | ||
context.done(); | ||
} | ||
); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "Azure" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"http": { | ||
"routePrefix": "api" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "serverless", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"mongodb": "^3.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
auth: { | ||
user: process.env.CosmosDBUser, | ||
password: process.env.CosmosDBPass | ||
} | ||
}; |