Skip to content

Commit

Permalink
Merge branch 'release/3.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
electerious committed May 21, 2022
2 parents ba976a8 + 2b905b9 commit 7d0196e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.

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).

## [3.4.1] - 2022-05-21

## Fixed

- Build failing on Netlify (thanks @adityatelange, #333)
- Vercel not attaching CORS headers because of unsupported `multiValueHeaders` (thanks @birjj, #330)
- `ACKEE_AUTO_ORIGIN` not attaching CORS headers (thanks @birjj, #330)

## [3.4.0] - 2022-05-15

### Added
Expand Down
28 changes: 27 additions & 1 deletion api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const handler = require('../src/serverless').handler

/**
* A serverless function handler for the '/api' route, for use with Vercel.
* This handler follows the AWS Lambda API; Vercel deployments are opted-in
Expand All @@ -9,4 +11,28 @@
* - https://vercel.com/docs/serverless-functions/supported-languages#node.js
* - https://vercel.com/docs/runtimes#advanced-usage/advanced-node-js-usage/aws-lambda-api
*/
exports.handler = require('../src/serverless').handler
exports.handler = async (...args) => {
const response = await handler(...args)
return convertMultiValueHeaders(response)
}

/*
* At the time of writing the Vercel polyfill for the AWS Lambda API doesn't support .multiValueHeaders.
* This stops us from attaching CORS headers to requests.
* Since all the headers we commonly attach have a single value, we can map them to .headers instead.
*/
const convertMultiValueHeaders = (response) => {
if (response?.multiValueHeaders == null) return response

response.headers = response.headers ?? {}

for (const [ key, value ] of Object.entries(response.multiValueHeaders)) {
if (value.length === 1) {
response.headers[key] = value[0]
} else {
console.warn(`multiValueHeaders is currently unsupported on Vercel. Header ${ key } will be ignored.`)
}
}

return response
}
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
publish = "dist"
command = "yarn build"
functions = "functions/"
environment = { NODE_VERSION = "14.9.0", NODE_ENV = "production" }
environment = { NODE_VERSION = "14.19.0", NODE_ENV = "production" }

[[redirects]]
from = "/api"
Expand All @@ -15,4 +15,4 @@
ACKEE_USERNAME = "ACKEE_USERNAME"
ACKEE_PASSWORD = "ACKEE_PASSWORD"
ACKEE_ALLOW_ORIGIN = "ACKEE_ALLOW_ORIGIN"
ACKEE_AUTO_ORIGIN = "ACKEE_AUTO_ORIGIN"
ACKEE_AUTO_ORIGIN = "ACKEE_AUTO_ORIGIN"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ackee",
"private": true,
"version": "3.4.0",
"version": "3.4.1",
"authors": [
"Tobias Reich <tobias@electerious.com>"
],
Expand Down
7 changes: 5 additions & 2 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const apolloServer = createApolloServer(ApolloServer, {
const origin = (origin, callback) => {
if (config.autoOrigin === true) {
fullyQualifiedDomainNames()
.then((names) => callback(null, names))
.then((names) => callback(
null,
names.flatMap((name) => [ `http://${ name }`, `https://${ name }`, name ]),
))
.catch((error) => callback(error, false))
return
}
Expand All @@ -41,7 +44,7 @@ const origin = (origin, callback) => {
}

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

Expand Down

1 comment on commit 7d0196e

@vercel
Copy link

@vercel vercel bot commented on 7d0196e May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ackee – ./

ackee-electerious.vercel.app
ackee-mocha.vercel.app
ackee-git-master-electerious.vercel.app

Please sign in to comment.