Git Product home page Git Product logo

feathersjs-serverless's Introduction

feathersjs-serverless

npm version Build Status

feathersjs connector to the Serverless framework ⚡️

Have you ever imagined building an application with feathersjs and deploying it using the Serverless Framework?

const feathers = require('@feathersjs/feathers')
const serverless = require('feathersjs-serverless')

const Todos = {
  find: async () => ([{
    description: 'Build a nice application'
  }, {
    description: 'Deploy it using Serverless'
  }])
}

const app = serverless(feathers())
  .use('todos', Todos)

module.exports.handler = app.handler()

feathersjs-serverless's People

Contributors

adrianovalente avatar dependabot[bot] avatar skinofstars avatar

Stargazers

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

Watchers

 avatar  avatar

feathersjs-serverless's Issues

Interference with Adapter Query Parameters

I was using the Prisma adapter and I came across a problem using the $ query parameters. Basically, they work if I run feathers as an express/feathers app, but they break when I run feathers as a feathersjs-serverless app. Something happens to the query parameters and they don't get parsed correctly for feathers adapters.

I originally posted in the feathers-prisma repo, but when I ran a bare express/feathers app and didn't have problems, I realized that the issues is probably with this codebase. (ps73/feathers-prisma#14).

Steps to reproduce

  • Tell us what broke. The more detailed the better.

I have created a basic feathers controller using this feathers-prisma adapter and have tried to use various query parameters with no success. I have tried various queries:

$select

The official feathers.js documentation says this should work, but:

trying: http://127.0.0.1:5057/spaces?$select[]=organization_id,$select[]=space_id
gives error: "Invalid query parameter $select[]"

Looking through the code, it looks like the "[]" is not seen, so removing that gets us farther, but still have an error:

trying: http://127.0.0.1:5057/spaces?$select=organization_id,$select=space_id
gives error: "$select.forEach is not a function"

The query $select value didn't get converted to an array... Am I missing something?

$sort

$sort via the official feathers documentation:

trying: http://127.0.0.1:5057/spaces?$limit=2&$sort[created_at]=-1
gives error: "Invalid query parameter $sort[created_at]"

$in

trying: 127.0.0.1:5057/spaces?organization_id[$in][]=60230961c459f31c3883c1f0&organization_id[$in][]=60230961c459f31c3883c1df
gives the error: Invalid `this.Model.findMany() ...
trying: 127.0.0.1:5057/spaces?organization_id[$in]=60230961c459f31c3883c1f0&organization_id[$in]=60230961c459f31c3883c1df
gives the error: Invalid `this.Model.findMany() ...
  • If you can, please create a simple example that reproduces the issue and link to a gist, jsbin, repo, etc.

spaces.class.ts

import { PrismaService, PrismaServiceOptions } from 'feathers-prisma';
import { Application } from '../../declarations';

interface Options extends PrismaServiceOptions {}

export class Spaces extends PrismaService {
  //eslint-disable-next-line @typescript-eslint/no-unused-vars
  constructor(options: Options, app: Application) {
    super(options, app.get('prisma'));
  }
}

spaces.service.ts

mport { ServiceAddons } from '@feathersjs/feathers';
import { Application } from '../../declarations';
import { Spaces } from './spaces.class';
import hooks from './spaces.hooks';

// Add this service to the service type index
declare module '../../declarations' {
  interface ServiceTypes {
    'spaces': Spaces & ServiceAddons<any>;
  }
}

export default function (app: Application): void {
  const options = {
    model: 'spaces',
    client: app.get('prisma'),
    paginate: app.get('paginate')
  };

  // Initialize our service with any options it requires
  app.use('/spaces', new Spaces(options, app));

  // Get our initialized service so that we can register hooks
  const service = app.service('spaces');

  service.hooks(hooks);
}

prisma model

model spaces {
  space_id          Int       @id @default(autoincrement())
  name              String?   @db.VarChar
  created_at        DateTime? @db.Timestamptz(6)
  description       String?
  organization_id   String?   @db.VarChar
  primary_color     String?   @db.VarChar
  secondary_color   String?   @db.VarChar

  @@index([organization_id], map: "spaces_link_organization_id_index")
}

Expected behavior

$select

Should select return only the organization_id and space_id's for the records.

$sort

Should sort by created_at descending

$in

Should return the records with the ids in the given array of ids.

Actual behavior

Errors:
Invalid query parameter, $select.forEach is not a function, or Invalid this.Model.findMany() ...`

System configuration

Tell us about the applicable parts of your setup.

This is a bare bones feather setup with no hooks. Using feathersjs-serverless.

Module versions (especially the part that's not working):

"dependencies": {
    "@feathersjs/configuration": "^4.5.15",
    "@feathersjs/errors": "^4.5.15",
    "@feathersjs/express": "^4.5.15",
    "@feathersjs/feathers": "^4.5.15",
    "@feathersjs/primus": "^4.5.15",
    "@feathersjs/socketio": "^4.5.15",
    "@feathersjs/transport-commons": "^4.5.15",
    "@prisma/client": "^3.15.2",
    "aws-serverless-express": "^3.4.0",
    "body-parser": "^1.20.1",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.13.2",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "ejs": "^3.1.8",
    "express": "^4.18.2",
    "feathersjs-serverless": "^0.3.1",
    "feathers-prisma": "^0.6.0",
    "helmet": "^5.1.1",
    "install": "^0.13.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.5.7",
    "serve-favicon": "^2.5.0",
    "serverless-express": "^2.0.12",
    "serverless-http": "^3.1.0",
    "winston": "^3.8.2",
    "ws": "^8.11.0"
  },

NodeJS version:
v16.18.0

Operating System:
OS/X M1

Browser Version:
Firefox, Chrome, Safari

React Native Version:
N/A

Module Loader:
N/A

I started it up as a pure express/feathers.js app not as a "feathersjs-serverless" app and it seems to behave correctly. There might be some nastiness around parsing query parameters when that module is in between the adapter, feathers and the request coming in.

Returning Internal server error when response uses callback

It looks like using the callback in the service response isn't working. Still sorting through what this issue might be, but...

I think the fix is, rather than using

return cb(null, {
   body: JSON.stringify({ data })
})

We should use

return {
   body: JSON.stringify({ data })
}

Though I'm not 100% sure why

Example

Hello!

Is there an example to make use of a featherjs generated API and this package?

I have already deployed to serverless, but cannot make use of any route from a brand new featherjs project API.

I am using port: 80

And I have tried routes like:
/dev/api
/dev/api/users
/dev/users

But no luck.

Maybe I need to configure something in the serverless.yml?

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.