simov / express-admin

MySQL, MariaDB, PostgreSQL, SQLite admin for Node.js
MIT License
1.17k stars 223 forks source link

Add setupServer to allow merging of existing express apps #66

Closed knownasilya closed 10 years ago

knownasilya commented 10 years ago

To merge with existing app do something like:

var express = require('express');
var admin = require('express-admin');
var path = require('path');
var vhost = require('vhost');
var app = express();
var env = process.env.NODE_ENV || 'development';
var domain = (env === 'development' ? 'localhost' : 'mydomain.com');
var adminConfigPath = path.join(process.cwd(), 'server/admin/config');

// middleware here..

admin.setupServer(adminConfigPath, function (err, setup) {
  if (err) {
    throw err;
  }

  // to make it work in development
  app.use(vhost('admin.' + domain, setup.app));
});

To make it work on admin.localhost add 127.0.0.1 admin.localhost to /etc/hosts, see here.

Also uses setupServer internally.

knownasilya commented 10 years ago

@simov looks like you just merged something similar. Can you confirm?

simov commented 10 years ago

Yes @knownasilya I added a shortcut a few days ago, but it wasn't pushed to master. And it's outlined inside the docs here

Note that it's best to mount the admin app before any of your site specific middlewares.

Also you still need to load all config files from outside, I'm not sure if I want to change that at the moment

knownasilya commented 10 years ago

Would be nice to be able to specify the config directory or to pass the config object for fine-tuned control.