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 56f4c96

Browse files
format code
1 parent 9f1bf3b commit 56f4c96

File tree

6 files changed

+116
-113
lines changed

6 files changed

+116
-113
lines changed

‎functions/app/index.js

Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,90 +8,91 @@ import customLogger from '../utils/logger'
88

99
/* My express App */
1010
export default function expressApp(functionName) {
11-
12-
const app = express()
13-
const router = express.Router()
14-
15-
// gzip responses
16-
router.use(compression())
17-
18-
// Set router base path for local dev
19-
const routerBasePath = (process.env.NODE_ENV === 'dev') ? `/${functionName}` : `/.netlify/functions/${functionName}/`
20-
21-
/* define routes */
22-
router.get('/', (req, res) => {
23-
const html = `
24-
<html>
25-
<head>
26-
<style>
27-
body {
28-
padding: 30px;
29-
}
30-
</style>
31-
</head>
32-
<body>
33-
<h1>Express via '${functionName}' ⊂◉‿◉つ</h1>
34-
35-
<p>I'm using Express running via a <a href='https://www.netlify.com/docs/functions/' target='_blank'>Netlify Function</a>.</p>
36-
37-
<p>Choose a route:</p>
38-
39-
<div>
40-
<a href='/.netlify/functions/${functionName}/users'>View /users route</a>
41-
</div>
42-
43-
<div>
44-
<a href='/.netlify/functions/${functionName}/hello'>View /hello route</a>
45-
</div>
46-
47-
<br/>
48-
<br/>
49-
50-
<div>
51-
<a href='/'>
52-
Go back to demo homepage
53-
</a>
54-
</div>
55-
56-
<br/>
57-
<br/>
58-
59-
<div>
60-
<a href='https://github.com/DavidWells/netlify-functions-express' target='_blank'>
61-
See the source code on github
62-
</a>
63-
</div>
64-
</body>
65-
</html>
66-
`
67-
res.send(html)
68-
})
69-
70-
router.get('/users', (req, res) => {
71-
res.json({
72-
users: [{
73-
name: 'steve'
74-
}, {
75-
name: 'joe',
76-
}]
77-
})
78-
})
79-
80-
router.get('/hello/', function(req, res){
81-
res.send('hello world')
82-
})
83-
84-
// Attach logger
85-
app.use(morgan(customLogger))
86-
87-
// Setup routes
88-
app.use(routerBasePath, router)
89-
90-
// Apply express middlewares
91-
router.use(cors())
92-
router.use(bodyParser.json())
93-
router.use(bodyParser.urlencoded({ extended: true }))
94-
95-
return app
11+
const app = express()
12+
const router = express.Router()
13+
14+
// gzip responses
15+
router.use(compression())
16+
17+
// Set router base path for local dev
18+
const routerBasePath = process.env.NODE_ENV === 'dev' ? `/${functionName}` : `/.netlify/functions/${functionName}/`
19+
20+
/* define routes */
21+
router.get('/', (req, res) => {
22+
const html = `
23+
<html>
24+
<head>
25+
<style>
26+
body {
27+
padding: 30px;
28+
}
29+
</style>
30+
</head>
31+
<body>
32+
<h1>Express via '${functionName}' ⊂◉‿◉つ</h1>
33+
34+
<p>I'm using Express running via a <a href='https://www.netlify.com/docs/functions/' target='_blank'>Netlify Function</a>.</p>
35+
36+
<p>Choose a route:</p>
37+
38+
<div>
39+
<a href='/.netlify/functions/${functionName}/users'>View /users route</a>
40+
</div>
41+
42+
<div>
43+
<a href='/.netlify/functions/${functionName}/hello'>View /hello route</a>
44+
</div>
45+
46+
<br/>
47+
<br/>
48+
49+
<div>
50+
<a href='/'>
51+
Go back to demo homepage
52+
</a>
53+
</div>
54+
55+
<br/>
56+
<br/>
57+
58+
<div>
59+
<a href='https://github.com/DavidWells/netlify-functions-express' target='_blank'>
60+
See the source code on github
61+
</a>
62+
</div>
63+
</body>
64+
</html>
65+
`
66+
res.send(html)
67+
})
68+
69+
router.get('/users', (req, res) => {
70+
res.json({
71+
users: [
72+
{
73+
name: 'steve',
74+
},
75+
{
76+
name: 'joe',
77+
},
78+
],
79+
})
80+
})
81+
82+
router.get('/hello/', function(req, res) {
83+
res.send('hello world')
84+
})
85+
86+
// Attach logger
87+
app.use(morgan(customLogger))
88+
89+
// Setup routes
90+
app.use(routerBasePath, router)
91+
92+
// Apply express middlewares
93+
router.use(cors())
94+
router.use(bodyParser.json())
95+
router.use(bodyParser.urlencoded({ extended: true }))
96+
97+
return app
9698
}
97-

‎functions/aws-serverless-express.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* example using https://github.com/awslabs/aws-serverless-express */
2-
import express from 'express'
32
import awsServerlessExpress from 'aws-serverless-express'
43
import binaryMimeTypes from './utils/binaryMimeTypes'
54
import expressApp from './app'
65

76
// We need to define our function name for express routes to set the correct base path
87
const functionName = 'aws-serverless-express'
8+
99
// Initialize express app
1010
const app = expressApp(functionName)
1111

@@ -15,4 +15,4 @@ const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes)
1515
// Export Lambda handler
1616
exports.handler = (event, context) => {
1717
return awsServerlessExpress.proxy(server, event, context)
18-
}
18+
}

‎functions/react-app/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react"
1+
import React from 'react'
22

33
const App = (props) => {
44
const list = props.data.map((user) => {

‎functions/react-app/usersData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'isomorphic-fetch'
22

3-
export default function Data() {
3+
export default function fetchUserData() {
44
return fetch('https://jsonplaceholder.typicode.com/users').then(data => data.json())
55
}

‎functions/serverless-http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ const functionName = 'serverless-http'
99
const app = expressApp(functionName)
1010

1111
// Export lambda handler
12-
exports.handler = serverless(app)
12+
exports.handler = serverless(app)

‎functions/standalone-aws-serverless-express-example.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,33 @@ app.use(morgan(customLogger))
2121

2222
router.get('/users', (req, res) => {
2323
res.json({
24-
users: [{
25-
name: 'steve'
26-
}, {
27-
name: 'joe',
28-
}]
24+
users: [
25+
{
26+
name: 'steve',
27+
},
28+
{
29+
name: 'joe',
30+
},
31+
],
2932
})
3033
})
3134

3235
router.get('/', (req, res) => {
33-
const html = `
34-
<html>
35-
<head>
36-
</head>
37-
<body>
38-
<h1>
39-
⊂◉‿◉つ I'm using Express in a lambda via '${functionName}'
40-
</h1>
36+
const html = `
37+
<html>
38+
<head></head>
39+
<body>
40+
<h1>
41+
⊂◉‿◉つ I'm using Express in a lambda via '${functionName}'
42+
</h1>
4143
42-
<a href='/.netlify/functions/${functionName}/users'>
43-
View users route
44-
</a>
45-
</body>
46-
</html>
47-
`
48-
// send back HTML
44+
<a href='/.netlify/functions/${functionName}/users'>
45+
View users route
46+
</a>
47+
</body>
48+
</html>
49+
`
50+
// send back HTML
4951
res.send(html)
5052
})
5153

@@ -62,5 +64,5 @@ const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes)
6264

6365
// Export lambda handler
6466
exports.handler = (event, context) => {
65-
return awsServerlessExpress.proxy(server, event, context)
66-
}
67+
return awsServerlessExpress.proxy(server, event, context)
68+
}

0 commit comments

Comments
(0)

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