Giter Club home page Giter Club logo

pocketcloudfunctions's Introduction

Pocket Cloud Functions

Clustered Express Server + Pocketbase

What is this project exactly?

This is a miniature cloud functions app (faas) like firebase functions, trying to achieve what Pocketbase does for BaaS.

Under the hood, main process spawns express instance in cluster mode and exposes request types like all, get, post... and pocketbase methods. Along with these also I'm planning to integrate with Pocketbase to trigger events like user creation and deletion.

It's written in TypeScript, but most definitions aren't completed since still trying to figure out how it's going to look like or work. If you like to test what's available so far, after installing packages, run npm run dev this will compile the typescript and run it.

There is a configuration file, you may make some changes there.

So far here is how it works;

  • There is a function in index.ts this spawns processes.
  • This process has to be in /src/functions/ folder.
  • There is a server.ts in /src/ folder, initiates the express.
  • You gotta run this line below in your /src/functions/index.js
import server from "../server.js";

As soon as you import this, this will run the express server and will return you these objects;

{
    http:{
        all:(req,res)=>{} // Express method
        get:(req,res)=>{} // Express method
        post:(req,res)=>{} // Express method
        delete:(req,res)=>{} // Express method
        put:(req,res)=>{} // Express method
        use:(req,res)=>{} // Express method
    },
    user:{
        onCreate:(user)=>{}, // Event to be called when a user is created
        onDelete:(user)=>{} // Event to be called when a user is deleted
    }   
}

What's In It?

There are some middleware are bundled with it, these are;

  • Cors
  • Helmet
  • Rate Limiter Flexible
  • Pocketbase Middleware

Pocketbase middleware extends request object with these objects;

    {
        // ...
        pb:{
            baseUrl,
            lang,
            admins,
            collections,
            files,
            settings,
        },
        user:{
            //...pb.authStore.model
        }
    }

So if any request contains req.headers.authorization this will be used to set pocketbase authstore so requests can be checked if sent by a specific user, or their data can be accessed.

Plans

  • I would like to add gRPC, if I can't; web requests to receive events from pocketbase server.
  • Creating single executable, with a tool like pkg.

Future of this project

This is a side hustle, may turn into something or not, feel free to fork, work on it, methodology here is might be wrong. If you are looking for something more robust and extendable check out fn project. Runs node.js, .net, go, java and python as serverless.

TODO

  • GitHub auto update

pocketcloudfunctions's People

Contributors

siniradam avatar

Stargazers

daqi avatar Jaron Wanderley avatar Pavel Rusakov avatar Earl Celis avatar imcode avatar Ramazan Sancar avatar  avatar Hasan Alkarnosy avatar Zain A. Habeeb avatar

Watchers

 avatar  avatar

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.