Skip to content

Instantly share code, notes, and snippets.

@steinathan
Last active October 24, 2019 08:10
Show Gist options
  • Save steinathan/bfcad7e5d07f57563dac24f0f38e5189 to your computer and use it in GitHub Desktop.
Save steinathan/bfcad7e5d07f57563dac24f0f38e5189 to your computer and use it in GitHub Desktop.
Run your backend code without managing servers, Create actions that are triggered by HTTP events - Proposal

Action as Service (AAS)

After looking at Cloud Functions

"Run your mobile backend code without managing servers, Create functions that are triggered by Firebase products, such as changes to data in the Realtime Database, new user sign-ups via Auth, and conversion events in Analytics."

This is a very good concept, machine actions solve this already but we are looking for a way on making it containerized and visualized.

The Idea

Machine actions respond to changes to data in Realtime, such changes can be triggered by HTTP request and socket requests only, these 'Machine Actions' might not be existing yet in a Javascript file unless invoked, these actions have a strict specification that are the same with the node machine specification.

Motivation

In the time of building applications for customers, we discovered that testing, hosting and scaling was a big problem, some clients don't actually want a very big application backend but they need to spin a server with little routes and actions, creating a whole sails applicaiton and hosting it seems like an overkill, so instead of creating multiple backends with different "sails application", one can just create and deploy their affected actions and boom! the problem is solved, now how this problem gets solved is another thing.

# creates a virtual project in the cloud
$ machine new projectName --template ecommerce 

The above command dynamically generates an ecommerce sails server on the fly and binds it to the account currently logged in, then the user is given a public url where his application sits.

actions are just regular machine action files but in a way that the user won't really know its just a dynamic sails application, one can create an action by either using the available GUI or terminal.

Benefits of cloud actions

  • Develop a backend without servers
  • Keeps your logic private and secure
  • Run your mobile backend code without managing servers
  • Low maintenance, etc

This is just like heroku but instead of providing hosting for different applications, we're providing solutions for seemless javascript machine actions that follow its specifications, users don't need to worry about scaling and other hosting factors, but just concentrate on how well they write the actions

Features of a cloud action

  • Customized responses
  • Automatic and manual routing
  • Extendable database drivers {uses waterline's numerous adapters}
  • REST & Socket enabled listeners
  • Scaling and deployment

Users will only pay for other services like S3, dynamoDB, cloud store etc, there would be a plugable interface to edit the generated sails files ..

FAQ's

  • How do i install depedencies?
    • just specify them in your package.json, AAS will automatically run the npm i command at every deployment you make, then from the action just require('...') the dependency - that's it.

...

Example actionrc.prod.yml

datastores:
  default:
    adapter: "sails-mysql"
    url: "mysql://user:password@host:port/database"
    ssl: true
    
models:
  migrate: safe
  cascadeOnDestroy: false

blueprints:
  shortcuts: false

security:
  cors:
    allowOrigins:
      - "https://example.com"

session:
  cookie:
    secure: true
    maxAge: "24 * 60 * 60 * 1000"

sockets:
  onlyAllowOrigins:
    - "https://example.com"
    - "https://staging.example.com"

log:
  level: debug

http:
  cache: "365.25 * 24 * 60 * 60 * 1000"
  trustProxy: true

port: 80

ssl: undefined

custom:
  baseUrl: "https://thepentecost.herokuapp.com"
  internalEmailAddress: "[email protected]"

Which can be converted to what sails will understand

https://nodeca.github.io/js-yaml/#yaml=ZGF0YXN0b3JlczoKICBkZWZhdWx0OgogICAgYWRhcHRlcjogInNhaWxzLW15c3FsIgogICAgdXJsOiAibXlzcWw6Ly91c2VyOnBhc3N3b3JkQGhvc3Q6cG9ydC9kYXRhYmFzZSIKICAgIHNzbDogdHJ1ZQogICAgCm1vZGVsczoKICBtaWdyYXRlOiBzYWZlCiAgY2FzY2FkZU9uRGVzdHJveTogZmFsc2UKCmJsdWVwcmludHM6CiAgc2hvcnRjdXRzOiBmYWxzZQoKc2VjdXJpdHk6CiAgY29yczoKICAgIGFsbG93T3JpZ2luczoKICAgICAgLSAiaHR0cHM6Ly9leGFtcGxlLmNvbSIKCnNlc3Npb246CiAgY29va2llOgogICAgc2VjdXJlOiB0cnVlCiAgICBtYXhBZ2U6ICIyNCAqIDYwICogNjAgKiAxMDAwIgoKc29ja2V0czoKICBvbmx5QWxsb3dPcmlnaW5zOgogICAgLSAiaHR0cHM6Ly9leGFtcGxlLmNvbSIKICAgIC0gImh0dHBzOi8vc3RhZ2luZy5leGFtcGxlLmNvbSIKCmxvZzoKICBsZXZlbDogZGVidWcKCmh0dHA6CiAgY2FjaGU6ICIzNjUuMjUgKiAyNCAqIDYwICogNjAgKiAxMDAwIgogIHRydXN0UHJveHk6IHRydWUKCnBvcnQ6IDgwCgpzc2w6IHVuZGVmaW5lZAoKY3VzdG9tOgogIGJhc2VVcmw6ICJodHRwczovL3RoZXBlbnRlY29zdC5oZXJva3VhcHAuY29tIgogIGludGVybmFsRW1haWxBZGRyZXNzOiAic3VwcG9ydEBleGFtcGxlLmNvbSIK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment