-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b08a596
Showing
10 changed files
with
523 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@app | ||
test-cors | ||
|
||
@cors | ||
allowOrigins https://example.com | ||
allowMethods GET,POST,OPTIONS | ||
allowHeaders Authorization,X-Custom-Header | ||
exposeHeaders Content-Length,X-Custom-Header | ||
maxAge 7200 | ||
allowCredentials true | ||
|
||
@http | ||
get /foo | ||
|
||
@macros | ||
architect/macro-http-api | ||
arc-macro-cors |
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,2 @@ | ||
node_modules/ | ||
sam.yaml |
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,4 @@ | ||
src/http | ||
.arc | ||
sam.json | ||
sam.yaml |
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 @@ | ||
package-lock=false |
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,51 @@ | ||
# arc-macro-cors | ||
|
||
Enable CORS for [Architect](https://arc.codes) HTTP APIs. | ||
|
||
## Ok..How?! | ||
|
||
Install: | ||
|
||
`npm i arc-macro-cors` | ||
|
||
And add to your .arc-file for default CORS settings: | ||
|
||
```arc | ||
@app | ||
myapp | ||
@cors | ||
@http | ||
get / | ||
get /foo | ||
post /foo | ||
@macros | ||
architect/macro-http-api #Required until HTTP APIs are default in arc | ||
arc-macro-cors | ||
``` | ||
Or configure specific CORS settings: | ||
|
||
```arc | ||
@app | ||
myapp | ||
@cors | ||
allowOrigins https://example.com | ||
allowMethods GET,POST,OPTIONS | ||
allowHeaders Authorization,X-Custom-Header | ||
exposeHeaders Content-Length,X-Custom-Header | ||
maxAge 7200 | ||
allowCredentials true | ||
@http | ||
get / | ||
get /foo | ||
post /foo | ||
@macros | ||
architect/macro-http-api #Required until HTTP APIs are default in arc | ||
arc-macro-cors | ||
``` | ||
|
||
See [AWS::Serverless::HttpApi/HttpApiCorsConfiguration](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-httpapi-httpapicorsconfiguration.html) for more information. |
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,29 @@ | ||
{ | ||
"name": "arc-macro-cors", | ||
"version": "1.0.0", | ||
"description": "Enable CORS for Architect HTTP APIs", | ||
"main": "src/macros/arc-macro-cors.js", | ||
"dependencies": { | ||
"@architect/utils": "^1.5.2" | ||
}, | ||
"scripts": { | ||
"lint": "xo --fix" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/thedersen/arc-macro-cors.git" | ||
}, | ||
"xo": { | ||
"prettier": true, | ||
"space": 2 | ||
}, | ||
"prettier": { | ||
"trailingComma": "es5" | ||
}, | ||
"author": "Thomas Pedersen <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@architect/macro-http-api": "^1.0.0", | ||
"xo": "^0.28.1" | ||
} | ||
} |
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,246 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Transform": "AWS::Serverless-2016-10-31", | ||
"Description": "Exported by architect/[email protected] on 2020-04-12T19:56:04.132Z", | ||
"Resources": { | ||
"GetFoo": { | ||
"Type": "AWS::Serverless::Function", | ||
"Properties": { | ||
"Handler": "index.handler", | ||
"CodeUri": "./src/http/get-foo", | ||
"Runtime": "nodejs12.x", | ||
"MemorySize": 1152, | ||
"Timeout": 5, | ||
"Environment": { | ||
"Variables": { | ||
"ARC_ROLE": { | ||
"Ref": "Role" | ||
}, | ||
"ARC_CLOUDFORMATION": { | ||
"Ref": "AWS::StackName" | ||
}, | ||
"ARC_APP_NAME": "test-cors", | ||
"ARC_HTTP": "aws_proxy", | ||
"NODE_ENV": "staging", | ||
"SESSION_TABLE_NAME": "jwe" | ||
} | ||
}, | ||
"Role": { | ||
"Fn::Sub": [ | ||
"arn:aws:iam::${AWS::AccountId}:role/${roleName}", | ||
{ | ||
"roleName": { | ||
"Ref": "Role" | ||
} | ||
} | ||
] | ||
}, | ||
"Events": { | ||
"GetFooEvent": { | ||
"Type": "HttpApi", | ||
"Properties": { | ||
"Path": "/foo", | ||
"Method": "GET", | ||
"ApiId": { | ||
"Ref": "TestCorsApi" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"GetIndex": { | ||
"Type": "AWS::Serverless::Function", | ||
"Properties": { | ||
"Handler": "index.handler", | ||
"CodeUri": "/Users/thomas/n/lib/node_modules/@architect/architect/node_modules/@architect/http-proxy/dist", | ||
"Runtime": "nodejs12.x", | ||
"MemorySize": 1152, | ||
"Timeout": 5, | ||
"Environment": { | ||
"Variables": { | ||
"ARC_ROLE": { | ||
"Ref": "Role" | ||
}, | ||
"ARC_CLOUDFORMATION": { | ||
"Ref": "AWS::StackName" | ||
}, | ||
"ARC_APP_NAME": "test-cors", | ||
"ARC_HTTP": "aws_proxy", | ||
"NODE_ENV": "staging", | ||
"SESSION_TABLE_NAME": "jwe" | ||
} | ||
}, | ||
"Role": { | ||
"Fn::Sub": [ | ||
"arn:aws:iam::${AWS::AccountId}:role/${roleName}", | ||
{ | ||
"roleName": { | ||
"Ref": "Role" | ||
} | ||
} | ||
] | ||
}, | ||
"Events": { | ||
"GetIndexEvent": { | ||
"Type": "HttpApi", | ||
"Properties": { | ||
"Path": "/", | ||
"Method": "GET", | ||
"ApiId": { | ||
"Ref": "TestCorsApi" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"StaticBucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"AccessControl": "PublicRead", | ||
"WebsiteConfiguration": { | ||
"IndexDocument": "index.html", | ||
"ErrorDocument": "404.html" | ||
} | ||
} | ||
}, | ||
"Role": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
}, | ||
"Policies": [ | ||
{ | ||
"PolicyName": "ArcGlobalPolicy", | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents", | ||
"logs:DescribeLogStreams" | ||
], | ||
"Resource": "arn:aws:logs:*:*:*" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"GetStatic": { | ||
"Type": "AWS::Serverless::Function", | ||
"Properties": { | ||
"Handler": "index.handler", | ||
"CodeUri": "/Users/thomas/dev/oss/arc/arc-macro-cors/node_modules/@architect/http-proxy/dist", | ||
"Runtime": "nodejs12.x", | ||
"MemorySize": 1152, | ||
"Timeout": 5, | ||
"Environment": { | ||
"Variables": { | ||
"ARC_ROLE": { | ||
"Ref": "Role" | ||
}, | ||
"ARC_CLOUDFORMATION": { | ||
"Ref": "AWS::StackName" | ||
}, | ||
"ARC_APP_NAME": "test-cors", | ||
"ARC_HTTP": "aws_proxy", | ||
"NODE_ENV": "staging", | ||
"SESSION_TABLE_NAME": "jwe", | ||
"ARC_STATIC_SPA": "false" | ||
} | ||
}, | ||
"Role": { | ||
"Fn::Sub": [ | ||
"arn:aws:iam::${AWS::AccountId}:role/${roleName}", | ||
{ | ||
"roleName": { | ||
"Ref": "Role" | ||
} | ||
} | ||
] | ||
}, | ||
"Events": { | ||
"GetStaticEvent": { | ||
"Type": "HttpApi", | ||
"Properties": { | ||
"Path": "/_static/{proxy+}", | ||
"Method": "GET", | ||
"ApiId": { | ||
"Ref": "TestCorsApi" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"TestCorsApi": { | ||
"Type": "AWS::Serverless::HttpApi", | ||
"Properties": { | ||
"FailOnWarnings": true, | ||
"CorsConfiguration": { | ||
"AllowOrigins": [ | ||
"https://example.com" | ||
], | ||
"AllowHeaders": [ | ||
"Authorization", | ||
"X-Custom-Header" | ||
], | ||
"ExposeHeaders": [ | ||
"Content-Length", | ||
"X-Custom-Header" | ||
], | ||
"AllowMethods": [ | ||
"GET", | ||
"POST", | ||
"OPTIONS" | ||
], | ||
"MaxAge": 7200, | ||
"AllowCredentials": true | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"BucketURL": { | ||
"Description": "Bucket URL", | ||
"Value": { | ||
"Fn::Sub": [ | ||
"http://${bukkit}.s3-website-${AWS::Region}.amazonaws.com", | ||
{ | ||
"bukkit": { | ||
"Ref": "StaticBucket" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"HTTP": { | ||
"Description": "API Gateway", | ||
"Value": { | ||
"Fn::Sub": [ | ||
"https://${idx}.execute-api.${AWS::Region}.amazonaws.com", | ||
{ | ||
"idx": { | ||
"Ref": "TestCorsApi" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
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,5 @@ | ||
@aws | ||
runtime nodejs12.x | ||
# memory 1152 | ||
# timeout 30 | ||
# concurrency 1 |
Oops, something went wrong.