0.2.7 • Published 4 years ago

@satheler/s12r v0.2.7

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Serverlessizer (S12R)

Serverlessize your Node.js backend application to main clouds providers. With this package you can run your application on the Function as a Service on many cloud providers with same configuration.

šŸ“‘ Overview

  1. šŸ“„ Installation
  2. ā˜ļø Supported Cloud Providers
  3. 🧩 Supported frameworks
  4. āš”ļø Serverless Framework
  5. šŸ“œ Licensing

šŸ“„ Installation

Serverlessizer library for Node can be installed via package manager.

# npm
npm install @satheler/s12r

# yarn
yarn add @satheler/s12r

ā˜ļø Supported Cloud Providers

The following is a list of the currently support cloud providers:

āœ… AWS Lambda
āœ… Azure Functions
šŸ§‘ā€šŸ’» Google Cloud Functions WIP
ā± IBM Cloud

🧩 Supported frameworks

The following sections is the currently support frameworks.

Adonis

  1. Add the code below in serverlessizer.ts on your project root.
import 'reflect-metadata'
import { ServerContract } from '@ioc:Adonis/Core/Server'
import { Ignitor } from '@adonisjs/core/build/standalone'
import Serverlessizer from '@satheler/s12r'

let server: ServerContract

async function bootstrapServer () {
  const ignitor = new Ignitor(__dirname)
  const httpServer = ignitor.httpServer()

  httpServer.application.setup()
  httpServer.application.registerProviders()
  httpServer.application.requirePreloads()
  await httpServer.application.bootProviders()

  const server = httpServer.application.container.use('Adonis/Core/Server')
  server.optimize()

  return server
}

export const handle = async (...args: any[]) => {
  if(!server) {
    server = await bootstrapServer()
  }

  const { request, response } = Serverlessizer(args)
  return server.handle(request, response)
}

Express (Coming soon)

Hapi (Coming soon)

LoopBack (Coming soon)

āš”ļø Serverless Framework

The Serverless Framework uses new event-driven compute services, like AWS Lambda, Google Cloud Functions, and more. It's a command-line tool, providing scaffolding, workflow automation and best practices for developing and deploying your serverless architecture.

Below has a example of serverless configuration with typescript. The project output in tsconfig.json is set as build.

Amazon Web Services (AWS)

This example already includes the Lambda Layer with node_modules folder.

serverless.aws.yml

service: your-service-name

provider:
  name: aws
  region: ${opt:region, 'sa-east-1'}
  stage: ${opt:stage, 'development'}
  runtime: nodejs14.x
  timeout: 10
  memorySize: 256
  versionFunctions: false
  environment:
    NODE_ENV: production
    MY_ENV_VARS: true

functions:
  app:
    handler: build/serverlessizer.handle
    layers:
      - { Ref: NodeModulesLambdaLayer }
    events:
      - http:
          cors: true
          path: '/'
          method: any
      - http:
          cors: true
          path: '{proxy+}'
          method: any

package:
  include:
    - build/**

  exclude:
    - '**/*.ts'
    - node_modules/**

layers:
  NodeModules:
    name: ${self:provider.apiName}-layer
    path: tmp/layers
    description: "node_modules dependencies"

Microsoft Azure

serverless.azure.yml

service: your-service-name

provider:
  name: azure
  region: ${opt:region, 'sa-east-1'}
  runtime: nodejs12
  stage: ${opt:stage, 'develop'}
  stackName: ${self:provider.stage}-${self:service}
  apiName: ${self:provider.stage}-${self:service}
  timeout: 10
  memorySize: 256
  versionFunctions: false
  apim: true
  environment:
    NODE_ENV: production
    MY_ENV_VARS: true

functions:
  app:
    handler: build/serverlessizer.handle
    events:
      - http: true
        route: '{*proxy}'
        authLevel: anonymous

package:
  include:
    - build/**

  exclude:
    - '**/*.ts'
    - node_modules/**
    - tmp/**
    - app/**

plugins:
  - serverless-azure-functions

šŸ“œ Licensing

Serverlessizer is licensed under the MIT License.

All files located in the node_modules and external directories are externally maintained libraries used by this software which have their own licenses; we recommend you read them, as their terms may differ from the terms in the MIT License.

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.7

4 years ago

0.1.4

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago