Feathers: can i mount feathers to my existing express app for api routes?

Created on 11 Feb 2017  路  5Comments  路  Source: feathersjs/feathers

pretty curious about this. your help is appreciated.

Most helpful comment

If you mean to use feathers as a sub app within an express server then you can do so by something like:

// server.js
import express from 'express';
import bodyParser from 'body-parser';
import api from './api';

const app = express();

const init = () => {
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use('/api', api);
  const server = app.listen(3001);
  api.setup(server);
};

export const run = () => init();
// api.js
import feathers from 'feathers';
import rest from 'feathers-rest';
import sequelize from 'feathers-sequelize';
import socketio from 'feathers-socketio';

const db = require('../feathers/models');
const api = feathers();

api.configure(socketio());
api.configure(rest());

api.use('/film', sequelize({
  Model: db.film,
  id: 'film_id',
  paginate: {
    default: 10,
    max: 25
  }
}));

export default api;

Now you can access the above at /api/film.

All 5 comments

If you mean to use feathers as a sub app within an express server then you can do so by something like:

// server.js
import express from 'express';
import bodyParser from 'body-parser';
import api from './api';

const app = express();

const init = () => {
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use('/api', api);
  const server = app.listen(3001);
  api.setup(server);
};

export const run = () => init();
// api.js
import feathers from 'feathers';
import rest from 'feathers-rest';
import sequelize from 'feathers-sequelize';
import socketio from 'feathers-socketio';

const db = require('../feathers/models');
const api = feathers();

api.configure(socketio());
api.configure(rest());

api.use('/film', sequelize({
  Model: db.film,
  id: 'film_id',
  paginate: {
    default: 10,
    max: 25
  }
}));

export default api;

Now you can access the above at /api/film.

wow thanks ill give it a try.

This works fully with the REST or Socket.IO feathers-client as well, and not just as URLs you can access on browser.

// client.js
import feathers from 'feathers/client';
import socketio from 'feathers-socketio/client';
import io from 'socket.io-client';

const host = 'http://localhost:3001';
const client = feathers().configure(socketio(io(host)));

export const filmService = client.service('/api/film');
export default client;

Thanks @zusamann that's exactly it.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vincz picture Vincz  路  4Comments

arve0 picture arve0  路  4Comments

perminder-klair picture perminder-klair  路  3Comments

jordanbtucker picture jordanbtucker  路  4Comments

rrubio picture rrubio  路  4Comments