11.0.0 • Published 1 year ago

fl-server-utils v11.0.0

Weekly downloads
9
License
MIT
Repository
github
Last release
1 year ago

Helper functions for the server side of FounderLab apps

backbone-rest render override example:

...
import { render } from 'fl-server-utils'

const detail = (applications, options, callback) => {
  // applications are a list of plain objects (not backbone models)
  callback(null, _.pick(applications, 'id'))
}
detail.$raw = true // flag it as raw

export default class ApplicationsController extends RestController {
  constructor(options) {
    super(options.app, _.defaults({
      model_type: Application,
      route: '/api/applications',
      auth: [...options.auth, createAuthMiddleware({canAccess})],
      templates: {
        detail: detail,
      },
      default_template: 'detail',
    }, options))
    // Overwrite the render method, making sure to bind it to the controller
    this.render = render.bind(this)
  }
}

cors

Middleware to add cors headers to all requests

// Remember to keep cors before auth middleware
import { cors } from 'fl-server-utils'
app.use(cors(config.origins || '*'))

smartSync

Auto select the correct type of BackboneORM sync based on the current database url. Use this to switch between e.g. mongodb and postgres without any code changes

import Backbone from 'backbone'
import { smartSync } from 'fl-server-utils'

const dbUrl = process.env.DATABASE_URL

export default class Task extends Backbone.Model {
  url = `${dbUrl}/tasks`

  schema = {

  }
}

// Use smartSync and it'll auto require the correct module
// Would normally look like e.g. `Task.prototype.sync = require('backbone-mongo').sync(Task)`
Task.prototype.sync = smartSync(dbUrl, Task)
11.0.0

1 year ago

10.0.0

1 year ago

9.0.0-rc.6

2 years ago

9.0.0-rc.4

2 years ago

9.0.0-rc.2

2 years ago

9.0.0

2 years ago

7.0.0

5 years ago

6.19.0

5 years ago

6.7.6

6 years ago

6.1.0

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.0.3

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

1.0.0

7 years ago

1.0.0-alpha.7

7 years ago

1.0.0-alpha.6

7 years ago

1.0.0-alpha.5

7 years ago

1.0.0-alpha.4

7 years ago

1.0.0-alpha.3

7 years ago

1.0.0-alpha.2

7 years ago

1.0.0-alpha.1

7 years ago

0.11.0

8 years ago

0.10.1

8 years ago

0.10.0

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago