{"id":24081782,"url":"https://github.com/jonathanconway/serverless-single-page-app-plugin","last_synced_at":"2025-06-11T15:32:48.322Z","repository":{"id":40376189,"uuid":"399132925","full_name":"jonathanconway/serverless-single-page-app-plugin","owner":"jonathanconway","description":"A plugin for Serverless Framework, to simplify deploying Single Page Application using S3 and CloudFront.","archived":false,"fork":false,"pushed_at":"2023-07-13T16:01:14.000Z","size":6,"stargazers_count":0,"open_issues_count":5,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-28T02:06:56.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonathanconway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-23T14:21:53.000Z","updated_at":"2021-08-23T14:41:12.000Z","dependencies_parsed_at":"2024-06-19T11:19:18.962Z","dependency_job_id":"3bc0443e-4de7-4d7d-bc0e-3f63a25fd51d","html_url":"https://github.com/jonathanconway/serverless-single-page-app-plugin","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.1428571428571429,"last_synced_commit":"d16854b268d3c77d6f6269629c21d4b4a315b378"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Fserverless-single-page-app-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Fserverless-single-page-app-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Fserverless-single-page-app-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Fserverless-single-page-app-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonathanconway","download_url":"https://codeload.github.com/jonathanconway/serverless-single-page-app-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Fserverless-single-page-app-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":257559787,"owners_count":22564650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-09T23:26:17.268Z","updated_at":"2025-06-11T15:32:48.271Z","avatar_url":"https://github.com/jonathanconway.png","language":"JavaScript","readme":"# serverless-single-page-app-plugin\n\nA plugin for [Serverless Framework](https://serverless.com), to simplify deploying Single Page Application using S3 and CloudFront.\n\nBased on the [official example](https://github.com/serverless/examples/tree/master/aws-node-single-page-app-via-cloudfront/serverless-single-page-app-plugin), with some important tweaks:\n\n* Auto-generated bucket name, to allow multiple independent deployments without name-clashes\n* Packaged as its own repo, so that it can be re-used and independently versioned\n\n## Installation\n\nInstall the package via NPM:\n\n```bash\nnpm install --save-dev https://github.com/jonathanconway/serverless-single-page-app-plugin/tarball\n```\n\nThen register it in your `serverless.yml` file, as a plugin:\n\n```\nplugins:\n  - serverless-single-page-app-plugin\n```\n\nAnd set an `s3LocalPath` custom variable:\n\n```\ncustom:\n  s3LocalPath: dist/\n```\n\nFinally, add appropriately-named resources (Bucket, BucketPolicy and Distribution) and Outputs:\n\n```\nresources:\n  Resources:\n    ## Specifying the S3 Bucket\n    WebAppS3Bucket:\n      Type: AWS::S3::Bucket\n      Properties:\n        AccessControl: PublicRead\n        WebsiteConfiguration:\n          IndexDocument: index.html\n          ErrorDocument: index.html\n    ## Specifying the policies to make sure all files inside the Bucket are avaialble to CloudFront\n    WebAppS3BucketPolicy:\n      Type: AWS::S3::BucketPolicy\n      Properties:\n        Bucket:\n          Ref: WebAppS3Bucket\n        PolicyDocument:\n          Statement:\n            - Sid: PublicReadGetObject\n              Effect: Allow\n              Principal: \"*\"\n              Action:\n              - s3:GetObject\n              Resource: \n                Fn::Join: [\n                  \"\", [\n                    \"arn:aws:s3:::\",\n                    { \"Ref\": \"WebAppS3Bucket\" },\n                    \"/*\"\n                  ]\n                ]\n    ## Specifying the CloudFront Distribution to server your Web Application\n    WebAppCloudFrontDistribution:\n      Type: AWS::CloudFront::Distribution\n      Properties:\n        DistributionConfig:\n          Origins:\n            - DomainName:\n                Fn::Join: [\n                  \"\", [\n                    { \"Ref\": \"WebAppS3Bucket\" },\n                    \".s3.amazonaws.com\"\n                  ]\n                ]\n              ## An identifier for the origin which must be unique within the distribution\n              Id: WebApp\n              CustomOriginConfig:\n                HTTPPort: 80\n                HTTPSPort: 443\n                OriginProtocolPolicy: https-only\n              ## In case you want to restrict the bucket access use S3OriginConfig and remove CustomOriginConfig\n              # S3OriginConfig:\n              #   OriginAccessIdentity: origin-access-identity/cloudfront/E127EXAMPLE51Z\n          Enabled: 'true'\n          ## Uncomment the following section in case you are using a custom domain\n          # Aliases:\n          # - mysite.example.com\n          DefaultRootObject: index.html\n          ## Since the Single Page App is taking care of the routing we need to make sure ever path is served with index.html\n          ## The only exception are files that actually exist e.h. app.js, reset.css\n          CustomErrorResponses:\n            - ErrorCode: 404\n              ResponseCode: 200\n              ResponsePagePath: /index.html\n          DefaultCacheBehavior:\n            AllowedMethods:\n              - DELETE\n              - GET\n              - HEAD\n              - OPTIONS\n              - PATCH\n              - POST\n              - PUT\n            ## The origin id defined above\n            TargetOriginId: WebApp\n            ## Defining if and how the QueryString and Cookies are forwarded to the origin which in this case is S3\n            ForwardedValues:\n              QueryString: 'false'\n              Cookies:\n                Forward: none\n            ## The protocol that users can use to access the files in the origin. To allow HTTP use `allow-all`\n            ViewerProtocolPolicy: redirect-to-https\n          ## The certificate to use when viewers use HTTPS to request objects.\n          ViewerCertificate:\n            CloudFrontDefaultCertificate: 'true'\n          ## Uncomment the following section in case you want to enable logging for CloudFront requests\n          # Logging:\n          #   IncludeCookies: 'false'\n          #   Bucket: mylogs.s3.amazonaws.com\n          #   Prefix: myprefix\n\n  ## In order to print out the hosted domain via `serverless info` we need to define the DomainName output for CloudFormation\n  Outputs:\n    WebAppS3BucketOutput:\n      Value:\n        'Ref': WebAppS3Bucket\n    WebAppCloudFrontDistributionOutput:\n      Value:\n        'Fn::GetAtt': [ WebAppCloudFrontDistribution, DomainName ]\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanconway%2Fserverless-single-page-app-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanconway%2Fserverless-single-page-app-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanconway%2Fserverless-single-page-app-plugin/lists"}