Skip to content

Instantly share code, notes, and snippets.

@toddgeist
Last active April 15, 2016 14:24
Show Gist options
  • Save toddgeist/226edfc544fe3fa5a3263b0fee668126 to your computer and use it in GitHub Desktop.
Save toddgeist/226edfc544fe3fa5a3263b0fee668126 to your computer and use it in GitHub Desktop.
feathers.js server composition ( sort of )
// src/app.js
const path = require('path');
const serveStatic = require('feathers').static;
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const feathers = require('feathers');
const configuration = require('feathers-configuration');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const middleware = require('./middleware');
const services = require('./services');
//--SUB APPS------------------------------------
// we give the mainAPP (ie this file ) the ability to constrol where the config is
// DB sub app
const fmConfig = path.join(__dirname, '..', 'apps', 'feathers-filemaker-rest')
const fmsREST = require('../apps/feathers-filemaker-rest/').config(fmConfig);
// API sub App
const apiConfig = path.join(__dirname, '..', 'apps', 'api')
const api = require('../apps/api/src/app').config(apiConfig)
//--------------------------------------------
// MAIN APP
// we do the same here for the main app for consistancy
const app = feathers();
const configureApp = (pathToConfig) => {
app.configure(configuration(pathToConfig));
app.use(compress())
.options('*', cors())
.use(cors())
.use(favicon( path.join(app.get('public'), 'favicon.ico') ))
.use('/', serveStatic( app.get('public') ))
.use('/db', fmsREST)
.use('/api/v1', api)
.configure(middleware);
return app
};
module.exports = app;
module.exports.config = configureApp;
// src/index.js
const path = require('path');
const configPath = path.join(__dirname, '..');
const app = require('./app').config(configPath);
const port = app.get('port');
const server = app.listen(port);
server.on('listening', () =>
console.log(`Feathers application started on ${app.get('host')}:${port}`)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment