Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Public asset returns 404 #130

Closed
barrysteyn opened this issue Aug 27, 2019 · 2 comments
Closed

Public asset returns 404 #130

barrysteyn opened this issue Aug 27, 2019 · 2 comments

Comments

@barrysteyn
Copy link
Contributor

Hi All

I am using version 2.3.3 of this plugin. I have a public folder with a file (file === hello.txt, content is hello world), however whenever I try serve that file, I get a 404. @danielcondemarin and @mattdell you can see a demonstration of this by going to https://sayy.it/hello.txt

Here is my setup:

service: sayyit-frontend

plugins:
  - serverless-nextjs-plugin
  - serverless-domain-manager
  - serverless-plugin-warmup
  - serverless-offline

custom:
  stage: ${self:provider.stage}
  memorySize: 256
  prefixes:
    RESOURCES_PREFIX: ${self:service.name}-${self:provider.stage}
  serverless-nextjs:
    cloudFrontConfig:
      prod:
        cloudFront: true
        assetsBucketName: sayyit-prod-static-assets
    assetsBucketName: ${self:custom.serverless-nextjs.cloudFrontConfig.${self:custom.stage}.assetsBucketName}
    cloudFront: ${self:custom.serverless-nextjs.cloudFrontConfig.${self:custom.stage}.cloudFront}
    nextConfigDir: ./
    staticDir: ./static
    customHandler: ./lambda-handler.js  
    routes:
      - src: category
        path: category/{id}/{slug}
        request:
          parameters:
            paths:
              id: true
              slug: true
      - src: topic
        path: topic/{id}/{slug}
        request:
          parameters:
            paths:
              id: true
              slug: true
      - src: profile
        path: profile/{id}/{slug}
        request:
          parameters:
            paths:
              id: true
              slug: true
  customDomain:
    staging:
      staging.sayy.it
    prod:
      sayy.it
    domainName: ${self:custom.customDomain.${self:custom.stage}}
    basePath: ''
    stage: ${self:custom.stage}
    createRoute53Record: true
  warmup:
    enabled: prod # Whether to warm up functions by default or not
    folderName: '_warmup' # Name of the folder created for the generated warmup
    cleanFolder: false
    memorySize: ${self:custom.memorySize}
    vpc: false
    events:
      - schedule: 'rate(10 minutes)' # Run WarmUp every 10 minutes
    timeout: 20
    prewarm: true # Run WarmUp immediately after a deploymentlambda
    concurrency: 10 # Warm up 10 concurrent instances

provider:
  name: aws
  runtime: nodejs10.x
  memorySize: ${self:custom.memorySize}
  timeout: 10
  stage: ${env:STAGE, 'staging'}
  tags:
    SERVICE: ${self:custom.prefixes.RESOURCES_PREFIX}
  region: ${opt:region, 'us-east-1'}
  iamRoleStatements:
    # Lambda Warmup functions
  - Effect: 'Allow'
    Action:
      - 'lambda:InvokeFunction'
    Resource:
    - Fn::Join:
      - ':'
      - - arn:aws:lambda
        - Ref: AWS::Region
        - Ref: AWS::AccountId
        - function:${self:service}-${self:provider.stage}-*

package:
  exclude:
    - ./**/*

What am I doing wrong?

@barrysteyn
Copy link
Contributor Author

Okay, so I realized that when I have cloudfront set to true, my public assets are not accessible. This was my problem. @danielcondemarin does this have to do with #95? Maybe I can update the documentation. BIG question: How would I get the public folder to work with cloudformation? I assume that I would need to use a domain for cloudformation?

@barrysteyn
Copy link
Contributor Author

Okay, I want to document what was my problem so that it can help other people. The problem is that I had the domain plugin for serverless installed, and it does not play nicely with domains for cloudfront. If someone is in the same situation: Remove your API gateway domain and disable the plugin for your cloudfront enabled stage (normally prod). Then follow the example and assign a domain to the cloudfront distribution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant