yamori
yamori

Reputation: 1243

NodeJS via Serverless, path(s) for public assets?

Just converted my NodeJS webapp to serverless, but I'm confused how to describe the access for the public/ folder (images, javascripts, stylesheets). I've seen syntax for {proxy+} and {id}, but the documentation I've read it's not clear if these apply to this situation. How do I make sure all the assets in my public/{images, javascripts, stylesheets} are correctly pathed in my serverless.yml?

Note: I've tried stylesheets/* in the serverless.yml but I get a String/type error.

The below is valid, but does not work when I try to access aws-apigw-blahblah.com/dev/stylesheets/custom.css, getting a "Missing Authentication Token".

    events: 
      - http: 
          path: /
          method: GET
          cors: true
      - http: 
          path: stylesheets
          method: GET
          cors: true

Upvotes: 0

Views: 414

Answers (1)

yamori
yamori

Reputation: 1243

(self answer after more research)

Serverless needs to off a webapp strictly from the point of view of an API, that is each http verb of GET, POST, etc. Any of the static content (images, custom JS) should be offered from another source such as S3. The serverless syntax doesn't accommodate events down to individual static assets, rather just the APIable verbs. See this AWS page, and the diagram with S3 flow at the top, and API-GW+Lambda at the bottom.

I extricated items from my public folder and put up on S3, and fit small bits of custom JS into the actual ejs file. Otherwise it would be a more complex deploy pipeline to update the S3 assets upon serverless deploy.

Upvotes: 1

Related Questions