-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from elliottsj/vercel
Support Vercel
- Loading branch information
Showing
9 changed files
with
94 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,7 @@ node_modules | |
|
||
# Dist folder | ||
dist/* | ||
!dist/.gitkeep | ||
!dist/.gitkeep | ||
|
||
# Vercel | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ env: | |
- YARN_GPG=no | ||
node_js: | ||
- 'node' | ||
- '12' | ||
- '14' | ||
os: | ||
- windows | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
|
||
/** | ||
* A serverless function handler for the '/api' route, for use with Vercel. | ||
* This handler follows the AWS Lambda API; Vercel deployments are opted-in | ||
* using the "NODEJS_AWS_HANDLER_NAME" environment variable defined in vercel.json. | ||
* | ||
* See: | ||
* - 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,9 @@ | ||
'use strict' | ||
|
||
const { ApolloServer } = require('apollo-server-lambda') | ||
const { UnsignedIntResolver, UnsignedIntTypeDefinition, DateTimeResolver, DateTimeTypeDefinition } = require('graphql-scalars') | ||
|
||
const connect = require('../src/utils/connect') | ||
const isDemoMode = require('../src/utils/isDemoMode') | ||
const isDevelopmentMode = require('../src/utils/isDevelopmentMode') | ||
const { createServerlessContext } = require('../src/utils/createContext') | ||
|
||
const allowOrigin = process.env.ACKEE_ALLOW_ORIGIN || '' | ||
const dbUrl = process.env.ACKEE_MONGODB || process.env.MONGODB_URI | ||
|
||
if (dbUrl == null) { | ||
throw new Error('MongoDB connection URI missing in environment') | ||
} | ||
|
||
connect(dbUrl) | ||
|
||
const apolloServer = new ApolloServer({ | ||
introspection: isDemoMode === true || isDevelopmentMode === true, | ||
playground: isDemoMode === true || isDevelopmentMode === true, | ||
debug: isDevelopmentMode === true, | ||
typeDefs: [ | ||
UnsignedIntTypeDefinition, | ||
DateTimeTypeDefinition, | ||
require('../src/types') | ||
], | ||
resolvers: { | ||
UnsignedInt: UnsignedIntResolver, | ||
DateTime: DateTimeResolver, | ||
...require('../src/resolvers') | ||
}, | ||
context: createServerlessContext | ||
}) | ||
|
||
exports.handler = apolloServer.createHandler({ | ||
cors: { | ||
origin: allowOrigin === '*' ? true : allowOrigin.split(','), | ||
methods: 'GET,POST,PATCH,OPTIONS', | ||
allowedHeaders: 'Content-Type' | ||
} | ||
}) | ||
/** | ||
* A serverless function handler for the '/api' route, for use with Netlify. | ||
* | ||
* See: | ||
* - https://docs.netlify.com/functions/overview/ | ||
*/ | ||
exports.handler = require('../src/serverless').handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,6 @@ | |
} | ||
}, | ||
"engines": { | ||
"node": ">= 14" | ||
"node": ">= 12" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict' | ||
|
||
const { ApolloServer } = require('apollo-server-lambda') | ||
const { UnsignedIntResolver, UnsignedIntTypeDefinition, DateTimeResolver, DateTimeTypeDefinition } = require('graphql-scalars') | ||
|
||
const connect = require('./utils/connect') | ||
const isDemoMode = require('./utils/isDemoMode') | ||
const isDevelopmentMode = require('./utils/isDevelopmentMode') | ||
const { createServerlessContext } = require('./utils/createContext') | ||
|
||
const allowOrigin = process.env.ACKEE_ALLOW_ORIGIN || '' | ||
const dbUrl = process.env.ACKEE_MONGODB || process.env.MONGODB_URI | ||
|
||
if (dbUrl == null) { | ||
throw new Error('MongoDB connection URI missing in environment') | ||
} | ||
|
||
connect(dbUrl) | ||
|
||
const apolloServer = new ApolloServer({ | ||
introspection: isDemoMode === true || isDevelopmentMode === true, | ||
playground: isDemoMode === true || isDevelopmentMode === true, | ||
debug: isDevelopmentMode === true, | ||
typeDefs: [ | ||
UnsignedIntTypeDefinition, | ||
DateTimeTypeDefinition, | ||
require('./types') | ||
], | ||
resolvers: { | ||
UnsignedInt: UnsignedIntResolver, | ||
DateTime: DateTimeResolver, | ||
...require('./resolvers') | ||
}, | ||
context: createServerlessContext | ||
}) | ||
|
||
exports.handler = apolloServer.createHandler({ | ||
cors: { | ||
origin: allowOrigin === '*' ? true : allowOrigin.split(','), | ||
methods: 'GET,POST,PATCH,OPTIONS', | ||
allowedHeaders: 'Content-Type' | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"build": { | ||
"env": { | ||
"NODEJS_AWS_HANDLER_NAME": "handler" | ||
} | ||
} | ||
} |