-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathfunctionBase.js
32 lines (24 loc) · 1.1 KB
/
functionBase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// TEMPLATE: This file will be copied to the Netlify functions directory when
// running next-on-netlify
// Render function for the Next.js page
const renderNextPage = require('./renderNextPage')
const base = async (event, context) => {
// x-forwarded-host is undefined on Netlify for proxied apps that need it
// fixes https://github.com/netlify/next-on-netlify/issues/46
if (!event.multiValueHeaders.hasOwnProperty('x-forwarded-host')) {
event.multiValueHeaders['x-forwarded-host'] = [event.headers['host']]
}
// Get the request URL
const { path } = event
console.log('[request]', path)
// Render the Next.js page
const response = await renderNextPage({ event, context })
// Convert header values to string. Netlify does not support integers as
// header values. See: https://github.com/netlify/cli/issues/451
Object.keys(response.multiValueHeaders).forEach((key) => {
response.multiValueHeaders[key] = response.multiValueHeaders[key].map((value) => String(value))
})
response.multiValueHeaders['Cache-Control'] = ['no-cache']
return response
}
module.exports = base