@certik/serverless-api 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.8
2
+
3
+ - fixed CORS
4
+
1
5
  # 1.0.7
2
6
 
3
7
  - fixed a typo in pack
package/lib/app.js CHANGED
@@ -2,7 +2,6 @@ import * as pulumi from "@pulumi/pulumi";
2
2
  import * as aws from "@pulumi/aws";
3
3
  import * as apigateway from "@pulumi/aws-apigateway";
4
4
  import { readFile } from "node:fs/promises";
5
- import { corsPreflight } from "./cors.js";
6
5
  import { isReservedEnvName } from "./env.js";
7
6
  import { packAndZip } from "./pack.js";
8
7
 
@@ -41,11 +40,6 @@ export async function createPulumiAPIApp({
41
40
  const wildcardCertificateName = getWildcardCertificateName(domainName);
42
41
  const lambdaRoleName = config.get("lambdaRole");
43
42
 
44
- // any route that has corsOrigin will have a preflight request
45
- if (routes.some((r) => r.corsOrigin)) {
46
- routes.push(corsPreflight());
47
- }
48
-
49
43
  const role = aws.iam.getRole({ name: lambdaRoleName });
50
44
 
51
45
  const sourceBucket = aws.s3.getBucket({ bucket: sourceBucketName });
package/lib/cors.js CHANGED
@@ -1,7 +1,7 @@
1
- export function corsPreflight() {
1
+ export function corsPreflight(name, path) {
2
2
  return {
3
- name: "cors-preflight",
4
- path: "/{proxy+}",
3
+ name,
4
+ path,
5
5
  method: "OPTIONS",
6
6
  timeout: 10,
7
7
  memorySize: 128,
package/lib/routes.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import pathModule from "node:path";
2
2
  import { readdir } from "node:fs/promises";
3
+ import { corsPreflight } from "./cors.js";
3
4
  import { DEFAULT_TIMEOUT, MAX_TIMEOUT, DEFAULT_MEMORY_SIZE } from "./const.js";
4
5
 
5
6
  export async function getRoutes(routeDirectory) {
@@ -13,7 +14,7 @@ export async function getRoutes(routeDirectory) {
13
14
  const methods = route.methods || ["GET"];
14
15
  const environmentVariables = route.environmentVariables || [];
15
16
 
16
- return methods.map((method) => ({
17
+ const methodRoutes = methods.map((method) => ({
17
18
  name: `${routeName}-${method}`,
18
19
  path: `/${routeName}`,
19
20
  method,
@@ -23,6 +24,14 @@ export async function getRoutes(routeDirectory) {
23
24
  memorySize: route.memorySize || DEFAULT_MEMORY_SIZE,
24
25
  environmentVariables,
25
26
  }));
27
+
28
+ if (route.corsOrigin) {
29
+ methodRoutes.push(
30
+ corsPreflight(`${routeName}-OPTIONS`, `/${routeName}`),
31
+ );
32
+ }
33
+
34
+ return methodRoutes;
26
35
  }),
27
36
  );
28
37
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "CertiK Engineering",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
- "version": "1.0.7",
7
+ "version": "1.0.8",
8
8
  "scripts": {
9
9
  "start": "doppler run -- nodemon start-dev.js",
10
10
  "lint": "eslint lib test routes *.js",