Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3ae4624

Browse files
update response
1 parent acca72f commit 3ae4624

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

‎functions/aws.js‎ renamed to ‎functions/aws-serverless-express.js‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import express from 'express'
22
import awsServerlessExpress from 'aws-serverless-express'
3-
4-
import bodyParser from 'body-parser'
53
import cors from 'cors'
4+
import bodyParser from 'body-parser'
65
import compression from 'compression'
76

87
const app = express()
@@ -12,22 +11,38 @@ router.use(compression())
1211

1312
router.get('/users', (req, res) => {
1413
res.json({
15-
hi: 'yo'
14+
users: [{
15+
name: 'steve'
16+
}, {
17+
name: 'joe',
18+
}]
1619
})
1720
})
1821

1922
router.get('/', (req, res) => {
2023
console.log('home route hit')
21-
res.json({
22-
express: 'here'
23-
})
24+
const html = `
25+
<html>
26+
<head>
27+
</head>
28+
<body>
29+
<h1>
30+
⊂◉‿◉つ I'm using Express in a lambda via 'aws-serverless-express'
31+
</h1>
32+
33+
<a href='/users'>View users route</a>
34+
</body>
35+
</html>
36+
`
37+
38+
res.send(html)
2439
})
2540

2641
router.get('/hello/', function(req, res){
2742
res.send('hello world')
2843
})
2944

30-
app.use('/.netlify/functions/aws/', router)
45+
app.use('/.netlify/functions/aws-serverless-express/', router)
3146

3247
router.use(cors())
3348
router.use(bodyParser.json())
@@ -52,6 +67,9 @@ const binaryMimeTypes = [
5267
'text/text',
5368
'text/xml'
5469
]
70+
5571
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes)
5672

57-
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)
73+
exports.handler = (event, context) => {
74+
return awsServerlessExpress.proxy(server, event, context)
75+
}

‎functions/serverless-http.js‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,31 @@ router.use(compression())
1212

1313
router.get('/users', (req, res) => {
1414
res.json({
15-
hi: 'yo'
15+
users: [{
16+
name: 'steve'
17+
}, {
18+
name: 'joe',
19+
}]
1620
})
1721
})
1822

1923
router.get('/', (req, res) => {
2024
console.log('home route hit')
21-
res.json({
22-
express: 'here'
23-
})
25+
const html = `
26+
<html>
27+
<head>
28+
</head>
29+
<body>
30+
<h1>
31+
⊂◉‿◉つ I'm using Express in a lambda via 'serverless-http'
32+
</h1>
33+
34+
<a href='/users'>View users</a>
35+
</body>
36+
</html>
37+
`
38+
39+
res.send(html)
2440
})
2541

2642
router.get('/hello/', function(req, res){

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /