@@ -8,90 +8,91 @@ import customLogger from '../utils/logger'
8
8
9
9
/* My express App */
10
10
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
96
98
}
97
-
0 commit comments