diff --git a/package.json b/package.json index 187d077..46468e7 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,10 @@ "author": "özer yilmaztekin ", "license": "UNLICENCED", "private": true, - "engines": { - "node" : ">=0.12" + "engines": { + "node": ">=0.12" }, - "engineStrict":true, + "engineStrict": true, "scripts": { "dev": "esw . && node server.js", "build": "next build", @@ -68,7 +68,8 @@ "react-scroll-up": "^1.3.3", "react-stickynode": "^2.1.1", "serverless-http": "^1.9.1", - "serverless-offline": "^4.9.4" + "serverless-offline": "^4.9.4", + "serverless-s3-sync": "^1.7.3" }, "devDependencies": { "@babel/core": "^7.2.2", diff --git a/serverless.yaml b/serverless.yaml index d918d2a..7e66e87 100644 --- a/serverless.yaml +++ b/serverless.yaml @@ -1,17 +1,172 @@ -service: serverless +service: nextjs-testing +package: + exclude: + - pages/** + - tests/** + - node_modules/.cache/** + - static/** + - .cache + - package.json + - yarn.lock + - package-lock.json + - "**.test.js" + - "__snapshots__/" + include: + - .next/** + +plugins: +- serverless-offline +- serverless-s3-sync + +custom: + endpointType: REGIONAL + region: "${opt:region, self:provider.region}" + stage: "${opt:stage, env:SLS_STAGE, 'dev'}" + serverless-offline: + port: 8000 + dontPrintOutput: true + bucket_name: "${self:service}-${self:custom.stage}-static" + s3Sync: + - bucketName: ${self:custom.bucket_name} + bucketPrefix: static/ + localDir: static + params: + - "**/*": + CacheControl: 'public, max-age=86400' + - bucketName: ${self:custom.bucket_name} + localDir: .next + bucketPrefix: _next/ + params: + - "**/*": + CacheControl: 'public, max-age=31536000, immutable' provider: name: aws runtime: nodejs8.10 + region: eu-west-1 + memorySize: 512 + timeout: 15 environment: NODE_ENV: production -plugins: - - serverless-offline - functions: - app: + nextJsApp: handler: lambdas/serverless.handler events: - - http: ANY / - - http: 'ANY {proxy+}' + - http: + path: / + method: ANY + - http: + path: /{any+} + method: ANY + +resources: + Description: Next.js testing in AWS lambda + Resources: + WebsiteBucketPolicy: + Type: "AWS::S3::BucketPolicy" + DependsOn: + - CDNOriginAccessIdentity + - WebsiteBucket + Properties: + Bucket: ${self:custom.bucket_name} + PolicyDocument: + Statement: + - Action: + - "s3:GetObject" + Effect: "Allow" + Resource: + Fn::Join: + - "" + - - Fn::GetAtt: [WebsiteBucket, Arn] + - "/*" + Principal: + CanonicalUser: + Fn::GetAtt: [CDNOriginAccessIdentity, S3CanonicalUserId] + + CDNOriginAccessIdentity: + Type: "AWS::CloudFront::CloudFrontOriginAccessIdentity" + Properties: + CloudFrontOriginAccessIdentityConfig: + Comment: + Fn::Join: + - "" + - - Ref: AWS::StackName + - "-origin-access-identity" + WebsiteBucket: + Type: AWS::S3::Bucket + DeletionPolicy: Delete + Properties: + BucketName: ${self:custom.bucket_name} + + CloudFrontDistribution: + Type: AWS::CloudFront::Distribution + DependsOn: + - WebsiteBucket + Properties: + DistributionConfig: + Origins: + - DomainName: + Fn::GetAtt: [WebsiteBucket, DomainName] + Id: WebsiteBucket + S3OriginConfig: + OriginAccessIdentity: + Fn::Join: + - "" + - - "origin-access-identity/cloudfront/" + - Ref: CDNOriginAccessIdentity + - DomainName: + Fn::Join: + - "" + - - Ref: ApiGatewayRestApi + - ".execute-api." + - ${self:custom.region} + - ".amazonaws.com" + Id: APIGWOrigin + OriginPath: "/${self:custom.stage}" + CustomOriginConfig: + OriginKeepaliveTimeout: 60 + OriginReadTimeout: 15 + HTTPPort: 80 + HTTPSPort: 443 + OriginProtocolPolicy: https-only + OriginSSLProtocols: + - 'TLSv1' + - 'TLSv1.1' + - 'TLSv1.2' + Enabled: 'true' + HttpVersion: http2 + CacheBehaviors: + - PathPattern: /_next/* + AllowedMethods: + - GET + - HEAD + - OPTIONS + TargetOriginId: WebsiteBucket + Compress: true + ForwardedValues: + QueryString: false + ViewerProtocolPolicy: https-only + - PathPattern: /static/* + AllowedMethods: + - GET + - HEAD + - OPTIONS + TargetOriginId: WebsiteBucket + Compress: true + ForwardedValues: + QueryString: false + ViewerProtocolPolicy: https-only + DefaultCacheBehavior: + AllowedMethods: + - GET + - HEAD + TargetOriginId: APIGWOrigin + Compress: true + MinTTL: 60 + DefaultTTL: 60 + ForwardedValues: + QueryString: true + Cookies: + Forward: none + ViewerProtocolPolicy: redirect-to-https \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index fc2a5cd..eec88a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1361,6 +1361,21 @@ "@types/istanbul-lib-coverage" "^2.0.0" "@types/yargs" "^12.0.9" +"@monolambda/s3@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@monolambda/s3/-/s3-1.0.2.tgz#7e1bd9dc339eed55f91a69a954dd3b2d67304ab9" + integrity sha512-AoDte0gKQR4cUTZ0h/W3BTchr0exYvXWreeLPCXNl0ZjH2VUr4GM1F+CcmGaM84MHSol1WQKqmV8eNtRkfEFBA== + dependencies: + aws-sdk "~2.89.0" + fd-slicer "~1.0.0" + findit2 "~2.2.3" + graceful-fs "~4.1.4" + mime "~1.2.11" + mkdirp "~0.5.0" + pend "~1.2.0" + rimraf "~2.2.8" + streamsink "~1.2.0" + "@mrmlnc/readdir-enhanced@^2.2.1": version "2.2.1" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" @@ -2713,6 +2728,22 @@ autoprefixer@^9.3.1: postcss "^7.0.14" postcss-value-parser "^3.3.1" +aws-sdk@~2.89.0: + version "2.89.0" + resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.89.0.tgz#dbf46999cbd5e74ce1b06640b07fa8e258ef07bc" + integrity sha1-2/RpmcvV50zhsGZAsH+o4ljvB7w= + dependencies: + buffer "4.9.1" + crypto-browserify "1.0.9" + events "^1.1.1" + jmespath "0.15.0" + querystring "0.2.0" + sax "1.2.1" + url "0.10.3" + uuid "3.0.1" + xml2js "0.4.17" + xmlbuilder "4.2.1" + aws-sign2@~0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" @@ -3202,7 +3233,7 @@ block-stream@*: dependencies: inherits "~2.0.0" -bluebird@^3.3.5, bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.3: +bluebird@^3.3.5, bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.2, bluebird@^3.5.3: version "3.5.4" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.4.tgz#d6cc661595de30d5b3af5fcedd3c0b3ef6ec5714" integrity sha512-FG+nFEZChJrbQ9tIccIfZJBz3J7mLrAhxakAbnrJWn8d7aKOC+LWifa0G+p4ZqKp4y13T7juYvdhq9NzKdsrjw== @@ -3405,7 +3436,7 @@ buffer-xor@^1.0.3: resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk= -buffer@^4.3.0: +buffer@4.9.1, buffer@^4.3.0: version "4.9.1" resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.1.tgz#6d1bb601b07a4efced97094132093027c95bc298" integrity sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg= @@ -4196,6 +4227,11 @@ cryptiles@^4.1.3: dependencies: boom "7.x.x" +crypto-browserify@1.0.9: + version "1.0.9" + resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-1.0.9.tgz#cc5449685dfb85eb11c9828acc7cb87ab5bbfcc0" + integrity sha1-zFRJaF37hesRyYKKzHy4erW7/MA= + crypto-browserify@^3.11.0: version "3.12.0" resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec" @@ -5297,6 +5333,11 @@ eventemitter3@^3.0.0, eventemitter3@^3.1.0: resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163" integrity sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA== +events@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924" + integrity sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ= + events@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/events/-/events-3.0.0.tgz#9a0a0dfaf62893d92b875b8f2698ca4114973e88" @@ -5562,6 +5603,13 @@ fbjs@^0.8.0, fbjs@^0.8.9: setimmediate "^1.0.5" ua-parser-js "^0.7.18" +fd-slicer@~1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.0.1.tgz#8b5bcbd9ec327c5041bf9ab023fd6750f1177e65" + integrity sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU= + dependencies: + pend "~1.2.0" + figgy-pudding@^3.5.1: version "3.5.1" resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790" @@ -5715,6 +5763,11 @@ find-up@^1.0.0: path-exists "^2.0.0" pinkie-promise "^2.0.0" +findit2@~2.2.3: + version "2.2.3" + resolved "https://registry.yarnpkg.com/findit2/-/findit2-2.2.3.tgz#58a466697df8a6205cdfdbf395536b8bd777a5f6" + integrity sha1-WKRmaX34piBc39vzlVNri9d3pfY= + flat-cache@^1.2.1: version "1.3.4" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.3.4.tgz#2c2ef77525cc2929007dfffa1dd314aa9c9dee6f" @@ -6092,7 +6145,7 @@ good-listener@^1.2.2: dependencies: delegate "^3.1.2" -graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6, graceful-fs@^4.1.9: +graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@~4.1.4: version "4.1.15" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00" integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA== @@ -7483,6 +7536,11 @@ jest@^24.0.0: import-local "^2.0.0" jest-cli "^24.7.1" +jmespath@0.15.0: + version "0.15.0" + resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.15.0.tgz#a3f222a9aae9f966f5d27c796510e28091764217" + integrity sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc= + joi@10.x.x: version "10.6.0" resolved "https://registry.yarnpkg.com/joi/-/joi-10.6.0.tgz#52587f02d52b8b75cdb0c74f0b164a191a0e1fc2" @@ -8341,6 +8399,11 @@ mime@^2.0.3, mime@^2.3.1: resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.2.tgz#ce5229a5e99ffc313abac806b482c10e7ba6ac78" integrity sha512-zJBfZDkwRu+j3Pdd2aHsR5GfH2jIWhmL1ZzBoc+X+3JEti2hbArWcyJ+1laC1D2/U/W1a/+Cegj0/OnEU2ybjg== +mime@~1.2.11: + version "1.2.11" + resolved "https://registry.yarnpkg.com/mime/-/mime-1.2.11.tgz#58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10" + integrity sha1-WCA+7Ybjpe8XrtK32evUfwpg3RA= + mimic-fn@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" @@ -9389,6 +9452,11 @@ pbkdf2@^3.0.3: safe-buffer "^5.0.1" sha.js "^2.4.8" +pend@~1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50" + integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA= + performance-now@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" @@ -10663,6 +10731,11 @@ rimraf@2, rimraf@2.6.3, rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6 dependencies: glob "^7.1.3" +rimraf@~2.2.8: + version "2.2.8" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582" + integrity sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI= + ripemd160@^2.0.0, ripemd160@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c" @@ -10780,7 +10853,12 @@ sass-loader@6.0.6: lodash.tail "^4.1.1" pify "^3.0.0" -sax@^1.2.4, sax@~1.2.4: +sax@1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.1.tgz#7b8e656190b228e81a66aea748480d828cd2d37a" + integrity sha1-e45lYZCyKOgaZq6nSEgNgozS03o= + +sax@>=0.6.0, sax@^1.2.4, sax@~1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== @@ -10934,6 +11012,16 @@ serverless-offline@^4.9.4: trim-newlines "^2.0.0" velocityjs "^1.1.3" +serverless-s3-sync@^1.7.3: + version "1.7.3" + resolved "https://registry.yarnpkg.com/serverless-s3-sync/-/serverless-s3-sync-1.7.3.tgz#a4da09f7fc6cff90c399bc5d30b8216b3c5469af" + integrity sha512-X5uuCdGz/xqi5aUVpXv3tYRL/BSdWJgs06Fuwp+alzcPWdHEqRwSdmGkWtZXSnACqPTfnf7EJGFSEQirLPNWjA== + dependencies: + "@monolambda/s3" "^1.0.2" + bluebird "^3.5.2" + chalk "^2.0.1" + minimatch "^3.0.4" + set-blocking@^2.0.0, set-blocking@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" @@ -11378,6 +11466,11 @@ stream-shift@^1.0.0: resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952" integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI= +streamsink@~1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/streamsink/-/streamsink-1.2.0.tgz#efafee9f1e22d3591ed7de3dcaa95c3f5e79f73c" + integrity sha1-76/unx4i01ke1949yqlcP1559zw= + string-hash@1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/string-hash/-/string-hash-1.1.3.tgz#e8aafc0ac1855b4666929ed7dd1275df5d6c811b" @@ -12164,6 +12257,14 @@ url-parse@^1.1.8, url-parse@^1.4.3: querystringify "^2.0.0" requires-port "^1.0.0" +url@0.10.3: + version "0.10.3" + resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64" + integrity sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ= + dependencies: + punycode "1.3.2" + querystring "0.2.0" + url@0.11.0, url@^0.11.0: version "0.11.0" resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1" @@ -12214,6 +12315,11 @@ utils-merge@1.0.1: resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM= +uuid@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" + integrity sha1-ZUS7ot/ajBzxfmKaOjBeK7H+5sE= + uuid@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" @@ -12671,6 +12777,21 @@ xml-name-validator@^3.0.0: resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a" integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw== +xml2js@0.4.17: + version "0.4.17" + resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.17.tgz#17be93eaae3f3b779359c795b419705a8817e868" + integrity sha1-F76T6q4/O3eTWceVtBlwWogX6Gg= + dependencies: + sax ">=0.6.0" + xmlbuilder "^4.1.0" + +xmlbuilder@4.2.1, xmlbuilder@^4.1.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-4.2.1.tgz#aa58a3041a066f90eaa16c2f5389ff19f3f461a5" + integrity sha1-qlijBBoGb5DqoWwvU4n/GfP0YaU= + dependencies: + lodash "^4.0.0" + xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"