const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const helmet = require('helmet');
const bodyParser = require('body-parser');

const feathers = require('feathers');
const configuration = require('feathers-configuration');
const hooks = require('feathers-hooks');
<% if (hasProvider('rest')) { %>const rest = require('feathers-rest');<% } %>
<% if (hasProvider('socketio')) { %>const socketio = require('feathers-socketio');<% } %>
<% if (hasProvider('primus')) { %>const primus = require('feathers-primus');<% } %>
const handler = require('feathers-errors/handler');
const notFound = require('feathers-errors/not-found');

const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');

const app = feathers();

// Load app configuration
app.configure(configuration(path.join(__dirname, '..')));
// Enable CORS, security, compression, favicon and body parsing
app.use(cors());
app.use(helmet());
app.use(compress());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
// Host the public folder
app.use('/', feathers.static(app.get('public')));
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);

// Set up Plugins and providers
app.configure(hooks());
<% if (hasProvider('rest')) { %>app.configure(rest());<% } %>
<% if (hasProvider('socketio')) { %>app.configure(socketio());<% } %>
<% if(hasProvider('primus')) { %>app.configure(primus({ transformer: 'websockets' }));<% } %>
// Set up our services (see `services/index.js`)
app.configure(services);
// Configure a middleware for 404s and the error handler
app.use(notFound());
app.use(handler());

app.hooks(appHooks);

module.exports = app;

@@ -1288,93 +1288,8 @@
 )));
-%0A// Configure other middleware (see %60middleware/index.js%60)%0Aapp.configure(middleware);
 %0A%0A//
@@ -1568,16 +1568,101 @@
 %3C%25 %7D %25%3E%0A
+// Configure other middleware (see %60middleware/index.js%60)%0Aapp.configure(middleware);%0A
 // Set u

Move middleware configuration in the right spot finally (#232)