-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for azure function v3 event source (#484)
Co-authored-by: brett-vendia <[email protected]>
- Loading branch information
1 parent
6baf1c2
commit a20cf01
Showing
20 changed files
with
1,236 additions
and
8 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
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
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,42 @@ | ||
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 | ||
|
||
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 |
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 @@ | ||
{ | ||
"recommendations": [ | ||
"ms-azuretools.vscode-azurefunctions" | ||
] | ||
} |
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,99 @@ | ||
const path = require('path') | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
const cors = require('cors') | ||
const compression = require('compression') | ||
const { getCurrentInvoke } = require('../../../src/index') // require('@vendia/serverless-express') | ||
const ejs = require('ejs').__express | ||
const app = express() | ||
const router = express.Router() | ||
|
||
app.set('view engine', 'ejs') | ||
app.engine('.ejs', ejs) | ||
|
||
router.use(compression()) | ||
router.use(cors()) | ||
router.use(bodyParser.json()) | ||
router.use(bodyParser.urlencoded({ extended: true })) | ||
|
||
// NOTE: tests can't find the views directory without this | ||
app.set('views', path.join(__dirname, 'views')) | ||
|
||
router.get('/api', (req, res) => { | ||
const currentInvoke = getCurrentInvoke() | ||
const { event = {} } = currentInvoke | ||
const { requestContext = {} } = event | ||
const { domainName = 'localhost:7071' } = requestContext | ||
const apiUrl = `https://${domainName}` | ||
res.render('index', { apiUrl }) | ||
}) | ||
|
||
router.get('/api/vendia', (req, res) => { | ||
res.sendFile(path.join(__dirname, 'vendia-logo.png')) | ||
}) | ||
|
||
router.get('/api/users', (req, res) => { | ||
res.json(users) | ||
}) | ||
|
||
router.get('/api/users/:userId', (req, res) => { | ||
const user = getUser(req.params.userId) | ||
|
||
if (!user) return res.status(404).json({}) | ||
|
||
return res.json(user) | ||
}) | ||
|
||
router.post('/api/users', (req, res) => { | ||
const user = { | ||
id: ++userIdCounter, | ||
name: req.body.name | ||
} | ||
users.push(user) | ||
res.status(201).json(user) | ||
}) | ||
|
||
router.put('/api/users/:userId', (req, res) => { | ||
const user = getUser(req.params.userId) | ||
|
||
if (!user) return res.status(404).json({}) | ||
|
||
user.name = req.body.name | ||
res.json(user) | ||
}) | ||
|
||
router.delete('/api/users/:userId', (req, res) => { | ||
const userIndex = getUserIndex(req.params.userId) | ||
|
||
if (userIndex === -1) return res.status(404).json({}) | ||
|
||
users.splice(userIndex, 1) | ||
res.json(users) | ||
}) | ||
|
||
router.get('/api/cookie', (req, res) => { | ||
res.cookie('Foo', 'bar') | ||
res.cookie('Fizz', 'buzz') | ||
res.json({}) | ||
}) | ||
|
||
const getUser = (userId) => users.find(u => u.id === parseInt(userId)) | ||
const getUserIndex = (userId) => users.findIndex(u => u.id === parseInt(userId)) | ||
|
||
// Ephemeral in-memory data store | ||
const users = [{ | ||
id: 1, | ||
name: 'Joe' | ||
}, { | ||
id: 2, | ||
name: 'Jane' | ||
}] | ||
let userIdCounter = users.length | ||
|
||
// The serverless-express library creates a server and listens on a Unix | ||
// Domain Socket for you, so you can remove the usual call to app.listen. | ||
// app.listen(3000) | ||
app.use('/', router) | ||
|
||
// Export your express server so you can import it in the lambda function. | ||
module.exports = app |
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,16 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"route": "{*segments}" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
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,7 @@ | ||
const serverlessExpress = require('../../../src/index') // require('@vendia/serverless-express') | ||
const app = require('./app') | ||
const cachedServerlessExpress = serverlessExpress({ app }) | ||
|
||
module.exports = async function (context, req) { | ||
return cachedServerlessExpress(context, req) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.