Git Product home page Git Product logo

serverless-aws-static-file-handler's Introduction

npm version npm Build Status Coverage Status License GitHub stars

serverless-aws-static-file-handler

Host the front-end of your web applications on Serverless framework on AWS Lambda right alongside the API.

It is a fast and easy way to get started and makes it trivial to deploy your web applications. If you need better response time in the future and get concerned about AWS costs of using Lambda to static content, you put CloudFront in front of your Serverless endpoints service static content.

Usage / Quick Start

Import & initialize:

const StaticFileHandler = require('serverless-aws-static-file-handler')

# configure where to serve files from:
const clientFilesPath = path.join(__dirname, "./data-files/")
const fileHandler = new StaticFileHandler(clientFilesPath)

Define a handler in your code as follows:

module.exports.html = async (event, context) => {
  event.path = "index.html" // forcing a specific page for this handler, ignore requested path. This would serve ./data-files/index.html
  return fileHandler.get(event, context)
}

In your serverless.yml file, reference the handler function from above to provide routes to your static files:

functions:
  html:
    handler: handler.html
    events:
      - http:
          path: /
          method: get

  # Note Binary files work too! See configuration information below
  png:
    handler: handler.png
    events:
      - http:
          path: png
          method: get

  # The following example uses a path placeholder to serve all files directly in the /binary/ directory:
  binary:
    handler: handler.binary
    events:
      - http:
        path: /binary/{pathvar+}
        method: get

To serve binary content make sure that you setup the plugin in your serverless.yml like so:

plugins:
  - serverless-aws-static-file-handler/plugins/BinaryMediaTypes

custom:
  apiGateway:
    binaryMediaTypes:
      - "image/png"
      - "image/jpeg"

Some additional real-world examples are demonstrated in the examples/basic/ directory as well as a serverless-offline-specific example in examples/serverless-offline/.

Prerequisites / Usage Requirements

Requires Node.js latest, LTS, or v10 (tested).

Requires Serverless Framework v1.x. If you are new to the Serverless Framework, check out the Serverless Framework Getting Started Guide.

Install

Install with yarn (yarn add serverless-aws-static-file-handler) or npm (npm install serverless-aws-static-file-handler --save-prod)

Features

  • Simple to get started
  • Works with text files such as HTML or binary files such as images or fonts

Contributing 🀝

This is a community project. We invite your participation through issues and pull requests! You can peruse the contributing guidelines.

Show your support

Give a ⭐️ if this project helped you!

Release Process (Deploying to NPM)

We use semantic-release to consistently release semver-compatible versions. This project deploys to multiple npm distribution tags. Each of the below branches correspond to the following npm distribution tags:

branch npm distribution tag
main latest
beta beta

To trigger a release use a Conventional Commit following Angular Commit Message Conventions on one of the above branches.

License πŸ“

Copyright Β© 2017 [email protected].

This project is MIT licensed.

serverless-aws-static-file-handler's People

Contributors

activescott avatar dependabot[bot] avatar greenkeeper[bot] avatar iodine- avatar piaverous avatar piroz avatar tomchiverton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

serverless-aws-static-file-handler's Issues

EMFILE: too many open files when running serverless deploy

Environment:

Win 10, 64bit.
Node v16.11.1
Serverless framework installed as a global package (npm i -g serverless)

Steps to reproduce the problem:

  1. Fresh Serverless project (serverless + npm init + git init)
  2. Run serverless deploy - all ok
  3. Run npm install serverless-aws-static-file-handler
  4. Run serverless deploy - sls process fails with
Serverless Error ----------------------------------------

  Cannot read file node_modules\tabtab\node_modules\rxjs\_esm5\internal\operators\distinctUntilKeyChanged.js due to: EMFILE: too many open files, open 'xxxxxx\node_modules\tabtab\node_modules\rxjs\_esm5\internal\operators\distinctUntilKeyChanged.js'

Actual behavior:

Upon inspection what is happening on disk, this package adds 673 dependency packages and 163MB to node_modules, including it installs once more serverless package with dependencies (again, I have it as a global package in the OS).

Expected behavior:

When I run npm i serverless-aws-static-file-handler it would not install serverless again with its dependencies.


I don't understand where all the dependencies really comes from, is it due sls being listed in peerDependencies? I could not find a way how to tell npm not to install those.

local e2e tests failed but the workflow doesn't fail

see #151 for an example of a PR where the local e2e tests failed but the workflow didn't report the failure to Github

Relevant portion of workflow run logs:
2022-08-03T19:34:02.8716113Z ##[group]Run "$GITHUB_WORKSPACE/test-files/scripts/test-local-e2e.sh"
2022-08-03T19:34:02.8716501Z οΏ½[36;1m"$GITHUB_WORKSPACE/test-files/scripts/test-local-e2e.sh"οΏ½[0m
2022-08-03T19:34:02.8776212Z shell: /usr/bin/bash -e {0}
2022-08-03T19:34:02.8776424Z env:
2022-08-03T19:34:02.8776635Z   SERVERLESS_STAGE: pr2778210674
2022-08-03T19:34:02.8776841Z ##[endgroup]
2022-08-03T19:34:02.8893028Z /home/runner/work/serverless-aws-static-file-handler/serverless-aws-static-file-handler/test-files/scripts/test-local-e2e.sh: 8: cd: can't cd to THISDIR
2022-08-03T19:34:02.8894024Z Using REPO_ROOT_DIR /home/runner/work/serverless-aws-static-file-handler/serverless-aws-static-file-handler
2022-08-03T19:34:02.8894584Z Running npm install...
2022-08-03T19:34:19.3727676Z added 562 packages from 483 contributors and audited 563 packages in 16.119s
2022-08-03T19:34:19.5507969Z 
2022-08-03T19:34:19.5508755Z 112 packages are looking for funding
2022-08-03T19:34:19.5509301Z   run `npm fund` for details
2022-08-03T19:34:19.5510027Z 
2022-08-03T19:34:19.5515295Z found 0 vulnerabilities
2022-08-03T19:34:19.5515663Z 
2022-08-03T19:34:19.5907337Z Running npm install completed.
2022-08-03T19:34:20.6576610Z Environment: linux, node 12.22.12, framework 3.21.0 (local), plugin 6.2.2, SDK 4.3.2
2022-08-03T19:34:20.6578779Z Error:
2022-08-03T19:34:20.6579726Z SyntaxError: Unexpected reserved word
2022-08-03T19:34:20.6580142Z Docs:        docs.serverless.com
2022-08-03T19:34:20.6580783Z     at Loader.moduleStrategy (internal/modules/esm/translators.js:140:18)
2022-08-03T19:34:20.6581176Z     at async link (internal/modules/esm/module_job.js:42:21)
2022-08-03T19:34:20.6582675Z Support:     forum.serverless.com
2022-08-03T19:34:20.6583031Z Bugs:        github.com/serverless/serverless/issues
2022-08-03T19:34:20.6583223Z 
2022-08-03T19:34:24.5954198Z EXPECT_CODE not specified; defaulting to 200
2022-08-03T19:34:24.5954686Z Testing http://localhost:3000/dev/binary/png.png for code 200...
2022-08-03T19:34:24.6205340Z 
2022-08-03T19:34:24.6206175Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.6207107Z *** http://localhost:3000/dev/binary/png.png *FAILED*. . Expected to have code 200 but was 000 ***
2022-08-03T19:34:24.6207549Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.6207767Z 
2022-08-03T19:34:24.6223101Z EXPECT_CODE not specified; defaulting to 200
2022-08-03T19:34:24.6223634Z Testing http://localhost:3000/dev/binary/jpg.jpg for code 200...
2022-08-03T19:34:24.6308940Z 
2022-08-03T19:34:24.6310807Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.6317439Z *** http://localhost:3000/dev/binary/jpg.jpg *FAILED*. . Expected to have code 200 but was 000 ***
2022-08-03T19:34:24.6317903Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.6318130Z 
2022-08-03T19:34:24.6326153Z EXPECT_CODE not specified; defaulting to 200
2022-08-03T19:34:24.6326976Z Testing http://localhost:3000/dev/binary/glyphicons-halflings-regular.woff2 for code 200...
2022-08-03T19:34:24.6409862Z 
2022-08-03T19:34:24.6410541Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.6411430Z *** http://localhost:3000/dev/binary/glyphicons-halflings-regular.woff2 *FAILED*. . Expected to have code 200 but was 000 ***
2022-08-03T19:34:24.6411957Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.6412151Z 
2022-08-03T19:34:24.6427094Z EXPECT_CODE not specified; defaulting to 200
2022-08-03T19:34:24.6427960Z Testing http://localhost:3000/dev/binary/subdir/png.png for code 200...
2022-08-03T19:34:24.6509804Z 
2022-08-03T19:34:24.6510751Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.6511241Z *** http://localhost:3000/dev/binary/subdir/png.png *FAILED*. . Expected to have code 200 but was 000 ***
2022-08-03T19:34:24.6511683Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.6511857Z 
2022-08-03T19:34:24.6527627Z Testing http://localhost:3000/dev/ff404.png for code 404...
2022-08-03T19:34:24.6648232Z 
2022-08-03T19:34:24.6648945Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.6650141Z *** http://localhost:3000/dev/ff404.png *FAILED*. . Expected to have code 404 but was 000 ***
2022-08-03T19:34:24.6713181Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.6713366Z 
2022-08-03T19:34:24.6713998Z Testing http://localhost:3000/dev/jpeg404.jpg for code 404...
2022-08-03T19:34:24.6802325Z 
2022-08-03T19:34:24.6803177Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.6803749Z *** http://localhost:3000/dev/jpeg404.jpg *FAILED*. . Expected to have code 404 but was 000 ***
2022-08-03T19:34:24.6804071Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.6804200Z 
2022-08-03T19:34:24.6820895Z Testing http://localhost:3000/dev/subdir404/ff.png for code 404...
2022-08-03T19:34:24.6914110Z 
2022-08-03T19:34:24.6914795Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.6915923Z *** http://localhost:3000/dev/subdir404/ff.png *FAILED*. . Expected to have code 404 but was 000 ***
2022-08-03T19:34:24.6916296Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.6916428Z 
2022-08-03T19:34:24.6934980Z Testing http://localhost:3000/dev/subdir/ff404.png for code 404...
2022-08-03T19:34:24.7020050Z 
2022-08-03T19:34:24.7020794Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.7022775Z *** http://localhost:3000/dev/subdir/ff404.png *FAILED*. . Expected to have code 404 but was 000 ***
2022-08-03T19:34:24.7023142Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.7023295Z 
2022-08-03T19:34:24.7074884Z Testing http://localhost:3000/dev/binary/404-glyphicons-halflings-regular.woff2 for code 404...
2022-08-03T19:34:24.7173274Z 
2022-08-03T19:34:24.7175366Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.7176451Z *** http://localhost:3000/dev/binary/404-glyphicons-halflings-regular.woff2 *FAILED*. . Expected to have code 404 but was 000 ***
2022-08-03T19:34:24.7177102Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.7177850Z 
2022-08-03T19:34:24.7192624Z Testing http://localhost:3000/dev/binary/subdir/404-png.png for code 404...
2022-08-03T19:34:24.7278391Z 
2022-08-03T19:34:24.7279429Z Λ…Λ…Λ…Λ…Λ… FAILURE Λ…Λ…Λ…Λ…Λ…
2022-08-03T19:34:24.7280264Z *** http://localhost:3000/dev/binary/subdir/404-png.png *FAILED*. . Expected to have code 404 but was 000 ***
2022-08-03T19:34:24.7280842Z ^^^^^ FAILURE ^^^^^
2022-08-03T19:34:24.7281371Z 
2022-08-03T19:34:24.7281792Z Killing serverless offline process...
2022-08-03T19:34:25.7674846Z Killing serverless offline process complete.

Depends on 5 megabytes of lodash just for _.get()

Adding this plugin balloons the deploy size.

Take the built .serverless/*.zip and unpack it

Observe the node_modules/* folder sizes. lodash is the biggest consumer at 5 meg

$ npm list -prod -all
npm WARN config production Use `--omit=dev` instead.
[email protected] /home/xxxxx/web-site
β”œβ”€β”¬ [email protected]
β”‚ β”œβ”€β”€ @types/[email protected]
β”‚ β”œβ”€β”¬ @types/[email protected]
β”‚ β”‚ └── @types/[email protected]
β”‚ β”œβ”€β”€ [email protected]
β”‚ └─┬ [email protected]
β”‚   β”œβ”€β”€ [email protected]
β”‚   β”œβ”€β”¬ [email protected]
β”‚   β”‚ β”œβ”€β”€ [email protected]
β”‚   β”‚ β”œβ”€β”€ [email protected]
β”‚   β”‚ β”œβ”€β”€ [email protected]
β”‚   β”‚ β”œβ”€β”€ [email protected]
β”‚   β”‚ β”œβ”€β”€ [email protected] deduped
β”‚   β”‚ β”œβ”€β”¬ [email protected]
β”‚   β”‚ β”‚ └── [email protected] deduped
β”‚   β”‚ └── [email protected]
β”‚   β”œβ”€β”€ [email protected]
β”‚   └── [email protected]
β”œβ”€β”¬ [email protected]
β”‚ β”œβ”€β”€ [email protected]
β”‚ β”œβ”€β”¬ [email protected]
β”‚ β”‚ └── [email protected]
β”‚ └── [email protected]
└── [email protected]

$ cd .serverless
... unzip *zip ...
$ cd */node_modules
$ du -skh *|sort -h| tail -n 2
724K    bluebird
5.0M    lodash

As far as I can see _.get() is the only thing used from all of lodash, it could be replaced with own impl.

[email protected]
node 18
Ubuntu 22.04 LTS

end-to-end tests don't run in CI anymore due to old lamda version

CREATE_FAILED: V2UnderscorehtmlLambdaFunction (AWS::Lambda::Function)
Resource handler returned message: "The runtime parameter of nodejs14.x is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (nodejs20.x) while creating or updating functions. (Service: Lambda, Status Code: 400, Request ID: a58efad3-ec65-4d44-bb2a-b923758690a0)" (RequestToken: 17cf8e39-5392-4257-c88f-96344b94afa9, HandlerErrorCode: InvalidRequest)

build in a serverless plugin for setting binaryMediaTypes to not require peer dependencies

See https://github.com/activescott/apigateway-lambda-binary-response#option-1-set-binarymediatypes-on-api

  • How configured?
  • Trace abandantly clear output to console when plugin is running
  • Remove serverless-apigwy-binary from peerDependencies
  • Add usage information to readme No BinaryMediaTypes configured. See https://github.com/activescott/serverless-aws-static-file-handler#usage for information on how to configure
  • In Demo

References:

chore: move package files into root rather than /src directory

I don't remember why it's like that but it has some odd side-effects. Like setting up lint to run in the whole repo is akward since package.json isn't in the root (and configuring prettier is a mess when using the dest path as ../) and the prepack/postpack section in package.json is a bizarre complication to get the readme into the package.

do it and merge to beta branch (which deploys a new serverless-aws-static-file-handler@beta package to npm and can test new package in examples that way.

minor.

An in-range update of prettier is breaking the build 🚨

The devDependency prettier was updated from 1.18.2 to 1.19.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for Prettier 1.19: Long awaited Vue option, TypeScript 3.7 and new JavaScript features

diff

πŸ”— Release Notes

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

binaryMediaTypes: */* in example causes issue with API Gateway CORS on OPTIONS request

FYI, the line in the example serverless file actually does cause an issue, with CORS when using API Gateway.

It causes the OPTIONS preflight cors check to fail with the error message { "message": "Internal server error" } as it gets inturpreted by the mock implementation as a binary field.

"- "*/*" # Using */* doesn't have side effects that I can tell. The HTML response works fine.

Update to work with v2 payload?

Not a bug, I was just trying to use the package and noticed it did not work with the API Gateway v2 payload format (https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).

What steps would be needed to adapt the package to work with v2?
For now I've noticed the event.path variable would no longer work, it has been replaced with event.rawPath, but I don't know enough about the code to think of other changes. I'm willing to help though.

Any guidance would be welcome!

2.0.2 -> 2.0.3 error message

After updating the NPM package from 2.0.2 to 2.0.3, the serverless command fails with this error:

Serverless plugin "serverless-aws-static-file-handler/plugins/BinaryMediaTypes" not found

When I downgrade back to 2.0.2, it goes away.

Is there any update needed for the config or might it be a regression bug?

When deployed on Lambda, image files are not able to be embedded as part of HTML

Hi, me again!
So I got my static website working great using Serverless Offline, but when I deploy it, something weird happens.

My endpoint serves binary files file (e.g. https://8rkav6rax2.execute-api.ap-southeast-1.amazonaws.com/stg/bin/dgwifi.png)

However when these are part of an HTML document (e.g. https://8rkav6rax2.execute-api.ap-southeast-1.amazonaws.com/stg/lp/index.html) they are not loaded. Text files work fine (CSS etc.) but there's something weird with Binary files. I guess its something weird in the headers. I experience a similar problem with fonts (.ttf files)

Have you run into this before? Any advice on how to fix this? My serverless.yml file is following your recommendation.

Thanks in advance!

Cheers,
Chris.

Unable to get Basic example to work

Expected behavior:

Deploy project

Actual behavior: Silently fails?

Steps to reproduce the problem:

Clone Basic example

Environment:

Dev

Please include version of serverless-aws-static-file-handler, version of serverless, version of node, and operating system name and version

Note: I also tried with "serverless-aws-static-file-handler": ">=3.0.1" & "serverless": "^2.50.0"

operating system name and version: macOs Catalina - v10.15.7 
serverless-aws-static-file-handler : "serverless-aws-static-file-handler": ">=2.0.4"
serverless
Framework Core: 2.49.0 (local)
Plugin: 5.4.3
SDK: 4.2.3
Components: 3.12.0
node v14.17.2
sls deploy
------------------
sls deploy
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: To ensure safe major version upgrades ensure "frameworkVersion" setting in service configuration (recommended setup: "frameworkVersion: ^2.49.0")

Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command config:tabcompletion
Serverless: Load command config:tabcompletion:install
Serverless: Load command config:tabcompletion:uninstall
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command upgrade
Serverless: Load command uninstall
Serverless: Load command deploy
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
Serverless: Load command output
Serverless: Load command output:get
Serverless: Load command output:list
Serverless: Load command param
Serverless: Load command param:get
Serverless: Load command param:list
Serverless: Load command studio
Serverless: Skipping variables resolution with old resolver (new resolver reported no more variables to resolve)
Serverless: Invoke deploy
Serverless: Warning: The command you entered did not catch on any hooks

serverless_aws_static_file_handler_1.default is not a constructor

Hi, I am trying to use this package in my Lambda Severless Repo to serve static html files likeso:

import StaticFileHandler from 'serverless-aws-static-file-handler';
import path = require('path');

const clientFilesPath = path.join(__dirname, './html/');
const fileHandler = new StaticFileHandler(clientFilesPath);

export const handler = async (event, _context) => {
event.path = 'index.html'; // forcing a specific page for this handler, ignore requested path. This would serve ./data-files/index.html
return fileHandler.get(event, _context);
};

But whenever I try to run the code , it shows me this error (during the run time):
Γ— serverless_aws_static_file_handler_1.default is not a constructor
Γ— TypeError: serverless_aws_static_file_handler_1.default is not a constructor

I tried looking at this module and found out that the constructor does exist but still not able to fix this.
constructor(clientFilesPath, customErrorPagePath = null) {
if (clientFilesPath == null || clientFilesPath.length === 0) {
throw new Error("clientFilesPath must be specified")
}
this.clientFilesPath = clientFilesPath
this.customErrorPagePath = customErrorPagePath
}

Any clue how can I solve this?

I am using typescript btw.

An in-range update of serverless-offline is breaking the build 🚨

The devDependency serverless-offline was updated from 5.10.0 to 5.10.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

serverless-offline is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v5.10.1

Bugfixes

  • TypeError: Cannot destructure property version of 'undefined' or 'null' #771
Commits

The new version differs by 2 commits.

  • f801d69 v5.10.1
  • b16c4f5 Remove underscore [bad cherry-pick from v6], fixes #771

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

The error message details does not appear in default and custom error pages

Expected behavior:

When an error occurs such as a missing page, the details about the error should be in the error page.

Actual behavior:

The text {errorText} appears where a detailed error message should be.

Steps to reproduce the problem:

Request a static file that will trigger a 404 page. You can use a custom page or the default error page.

Unicode support

Expected behavior:

Can place UTF8 characters such as ⏲️ in a .html file and they render as-is after output

Actual behavior:

Γ’οΏ½Β²Γ―ΒΈοΏ½

Steps to reproduce the problem:

import StaticFileHandler from 'serverless-aws-static-file-handler';

import { dirname,join as pathjoin} from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

const clientFilesPath = pathjoin(__dirname,"./public/")
const fileHandler = new StaticFileHandler(clientFilesPath);

export async function importTest(event,context){
	return fileHandler.get(event, context);
}

where public/index.html is as above

Environment:

serverless-aws-static-file-handler 4.0.2
node 18.12.1, framework 3.25.1 (local) 3.25.1v (global), plugin 6.2.2, SDK 4.3.2
Ubuntu 22.04 LTS

due to github secrets restrictions PRs from forks cannot run e2e tests

As described here PRs submitted by forks no longer have access to secrets so the E2E test which uses secrets for the AWS keys no longer works. This kinda defeats the purpose of github actions on any tests not local to the runner itself. I'm not sure what the solution to this is yet, but it would be nice to fix it.

Example at: https://github.com/activescott/serverless-aws-static-file-handler/runs/4677628418?check_suite_focus=true#step:6:22

Infinite loop of error page loading if error page is missing in custom builds

Hi, when custom build is used (e.g. using webpack) and error.html is not added to the build, requests to missing file cause infinite loading of error.html file.

Expected behavior:

  • missing error.html is detected and .get() rejects returned promise
  • or contents of error.html are inlined into code
  • or at least add information about the importance of including error.html in the final build into README

Actual behavior:

  • infinite loop of loading of error.html

Steps to reproduce the problem:

  • use webpack to create custom build
  • don't include error.html in the build
  • request missing file

No Cors headers present.

Expected behavior:

Serve static Files with cors enabled. No cors headers present.

Actual behavior:

Cors error:

Access to XMLHttpRequest at 'https://[URL]' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Steps to reproduce the problem:

Serve the static file:

event.path = file;
Return fileHandler.get(event, context);

Bonus Workaround

Adding the headers it worked but I need to access to the response object.

event.path = file;
let response = await fileHandler.get(event, context)
response.headers = {
   'Content-Type': response.headers["Content-Type"],
   'Access-Control-Allow-Methods': '*',
   'Access-Control-Allow-Origin': '*'
}
return response;

Environment:

OS: Debian 10 Buster

Node Version: 10.15.3

serverless-aws-static-file-handler Version: 2.0.4

Binary files using serverless-offline

Hi,
This project is perfect for me and I'm trying to get it to work using serverless-offline before publishing to AWS Lambda.
One thing I notice is that HTML files are served correctly with all appropriate headers, but Binary files return only the file (in base64 encoding I think) but without all the relevant headers (content-type etc.) so I cannot see the image in Postman / web browser etc. when invoking locally.
Is this an issue with serverless-offline, or is there some other reason why binary files are passed without headers?
Is there any trick I can do to test this locally, instead of deploying the whole thing every time?

Thanks so much!
Chris.

chore: pr-auto-merge-dependabot wasn't running due to invalid version reference

Expected behavior:

The workflow at https://github.com/activescott/serverless-aws-static-file-handler/blob/main/.github/workflows/pr-auto-merge-dependabot.yml runs without error.

Actual behavior:

Error: Unable to resolve action alexwilson/enable-github-automerge-action@f4f9509, the provided ref f4f9509 is the shortened version of a commit SHA, which is not supported.
See https://github.com/activescott/serverless-aws-static-file-handler/actions/runs/3641442438/jobs/6147377313

Steps to reproduce the problem:

Submit a PR

serverless listed as a dependency

serverless should be listed as a devdependency to avoid unnecessary bundling of it into deployment packages of consuming applications. serverless-aws-static-file-handler is currently adding 15MB to my deployment package because of this.

travis CI support for builds and npm deployment

  • set version number appropriately (from travis) - Set by git tag. Tag it with a semver on master and it deploys
  • only from master branch
  • only when commit was tagged as "publish"
  • publish release to github as draft (well, this is done by tagging the repo in the first place to trigger the npm deploy. see .travis.yml)
  • publish to npm

The 404 error page renders literal {errorText}

Expected behavior:

The 404 result presents the actual internal error text in development environments

Actual behavior:

Literal {errorText} is rendered which is a bit less than useful for debugging purposes.

Steps to fix the problem:

In async responseAsError(errorText, statusCode) replace

  <body>
    {{errorText}}
  </body>

with

  <body>
    ${errorText}
  </body>

or similar.

Exclusively support Lambda proxy integration and drop support for Lambda custom integration.

Major update focusing on misc improvements that can be unlocked by optimizing exclusively for Lambda proxy integration and dropping support for Lambda custom integration.

For more information on the difference between the two integration types see:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.