Skip to content

Commit 7d0196e

Browse files
committed
Merge branch 'release/3.4.1'
2 parents ba976a8 + 2b905b9 commit 7d0196e

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [3.4.1] - 2022-05-21
8+
9+
## Fixed
10+
11+
- Build failing on Netlify (thanks @adityatelange, #333)
12+
- Vercel not attaching CORS headers because of unsupported `multiValueHeaders` (thanks @birjj, #330)
13+
- `ACKEE_AUTO_ORIGIN` not attaching CORS headers (thanks @birjj, #330)
14+
715
## [3.4.0] - 2022-05-15
816

917
### Added

Diff for: api/index.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict'
22

3+
const handler = require('../src/serverless').handler
4+
35
/**
46
* A serverless function handler for the '/api' route, for use with Vercel.
57
* This handler follows the AWS Lambda API; Vercel deployments are opted-in
@@ -9,4 +11,28 @@
911
* - https://vercel.com/docs/serverless-functions/supported-languages#node.js
1012
* - https://vercel.com/docs/runtimes#advanced-usage/advanced-node-js-usage/aws-lambda-api
1113
*/
12-
exports.handler = require('../src/serverless').handler
14+
exports.handler = async (...args) => {
15+
const response = await handler(...args)
16+
return convertMultiValueHeaders(response)
17+
}
18+
19+
/*
20+
* At the time of writing the Vercel polyfill for the AWS Lambda API doesn't support .multiValueHeaders.
21+
* This stops us from attaching CORS headers to requests.
22+
* Since all the headers we commonly attach have a single value, we can map them to .headers instead.
23+
*/
24+
const convertMultiValueHeaders = (response) => {
25+
if (response?.multiValueHeaders == null) return response
26+
27+
response.headers = response.headers ?? {}
28+
29+
for (const [ key, value ] of Object.entries(response.multiValueHeaders)) {
30+
if (value.length === 1) {
31+
response.headers[key] = value[0]
32+
} else {
33+
console.warn(`multiValueHeaders is currently unsupported on Vercel. Header ${ key } will be ignored.`)
34+
}
35+
}
36+
37+
return response
38+
}

Diff for: dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: netlify.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
publish = "dist"
33
command = "yarn build"
44
functions = "functions/"
5-
environment = { NODE_VERSION = "14.9.0", NODE_ENV = "production" }
5+
environment = { NODE_VERSION = "14.19.0", NODE_ENV = "production" }
66

77
[[redirects]]
88
from = "/api"
@@ -15,4 +15,4 @@
1515
ACKEE_USERNAME = "ACKEE_USERNAME"
1616
ACKEE_PASSWORD = "ACKEE_PASSWORD"
1717
ACKEE_ALLOW_ORIGIN = "ACKEE_ALLOW_ORIGIN"
18-
ACKEE_AUTO_ORIGIN = "ACKEE_AUTO_ORIGIN"
18+
ACKEE_AUTO_ORIGIN = "ACKEE_AUTO_ORIGIN"

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ackee",
33
"private": true,
4-
"version": "3.4.0",
4+
"version": "3.4.1",
55
"authors": [
66
"Tobias Reich <[email protected]>"
77
],

Diff for: src/serverless.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ const apolloServer = createApolloServer(ApolloServer, {
2121
const origin = (origin, callback) => {
2222
if (config.autoOrigin === true) {
2323
fullyQualifiedDomainNames()
24-
.then((names) => callback(null, names))
24+
.then((names) => callback(
25+
null,
26+
names.flatMap((name) => [ `http://${ name }`, `https://${ name }`, name ]),
27+
))
2528
.catch((error) => callback(error, false))
2629
return
2730
}
@@ -41,7 +44,7 @@ const origin = (origin, callback) => {
4144
}
4245

4346
exports.handler = (event, context) => {
44-
// Set request context which is missing on Vercel
47+
// Set request context which is missing on Vercel:
4548
// https://stackoverflow.com/questions/71360059/apollo-server-lambda-unable-to-determine-event-source-based-on-event
4649
if (event.requestContext == null) event.requestContext = context
4750

0 commit comments

Comments
 (0)