Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Add templates for asset-functions that serve Javascript and CSS #6

Closed
parruda opened this issue Feb 3, 2019 · 2 comments
Closed

Add templates for asset-functions that serve Javascript and CSS #6

parruda opened this issue Feb 3, 2019 · 2 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@parruda
Copy link

parruda commented Feb 3, 2019

The idea is to create a template for the command faastruby new that would initialize a folder with a function already prepared to serve Javascript and CSS.
The command could be, for example:

~$ faastruby new FUNCTION_NAME --template assets

Note that we must have templates for all the supported runtimes (--runtime).

The resulting folder could look like this:

function_folder
├── assets
│   ├── javascript
│   │   └── application.js
│   └── stylesheets
│       └── application.css
├── spec
│   ├── handler_spec.rb
│   └── spec_helper.rb
├── Gemfile
└── handler.rb

Example requests:

  • /workspace-name/function-name?css=application.css
  • /workspace-name/function-name?js=application.js

And an example Ruby function could be like:

def handler(event)
  return render(css: File.read("assets/stylesheets/#{event.query_params['css']}")) if event.query_params.has_key?('css')
  return render(js: File.read("assets/javascript/#{event.query_params['js']}")) if event.query_params.has_key?('js')
end

There's also the need for sanitizing the input. For example, we don't want to allow js=../foo.js (which would not result in anything bad because the platform is secured against stuff like that - but it is better to avoid anyways). So there's a need for some sort of regular expression to remove everything fromcss= and js= but letters, numbers, dashes, underlines and one period.
The above is just a suggestion. Feel free to propose something better.

@parruda parruda added help wanted Extra attention is needed good first issue Good for newcomers labels Feb 3, 2019
@parruda parruda changed the title Add templates for asset-functions that carry Javascript and CSS Add templates for asset-functions that serve Javascript and CSS Feb 3, 2019
@parruda
Copy link
Author

parruda commented Feb 3, 2019

It would also be great if this could create a function from a template that is hosted in a remote Git repository. For example:

~$ faastruby new FUNCTION_NAME --template github:parruda/faastruby-assets-template

@parruda
Copy link
Author

parruda commented Feb 3, 2019

Closed in favor of #8

@parruda parruda closed this as completed Feb 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant