acdd22988a
* ui: Adds some express middleware, removes need to run api dev server @hashicorp/api-double comes with a basic express based server to run the API double. This uses the express based server that ember-cli includes and uses to run your app instead. Eventually this will be moved to the @hashicorp/ember-cli-api-double addon instead. * Adds `make start-consul` to ease running a dev UI against Consul itself
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
/* eslint-env node */
|
|
'use strict';
|
|
//
|
|
const $ = process.env;
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const promisify = require('util').promisify;
|
|
const read = promisify(fs.readFile);
|
|
const apiDouble = require('@hashicorp/api-double');
|
|
|
|
const apiDoubleHeaders = require('@hashicorp/api-double/lib/headers');
|
|
const cookieParser = require('cookie-parser');
|
|
const bodyParser = require('body-parser');
|
|
//
|
|
module.exports = {
|
|
name: 'startup',
|
|
serverMiddleware: function(server) {
|
|
// TODO: This should all be moved out into ember-cli-api-double
|
|
// and we should figure out a way to get to the settings here for
|
|
// so we can set this path name centrally in config
|
|
// TODO: undefined here is a possible faker salt that we should be able
|
|
// to pass in from ember serve/config somehow
|
|
const dir = path.resolve('./node_modules/@hashicorp/consul-api-double');
|
|
const controller = apiDouble(undefined, dir, read, $, path.resolve);
|
|
[
|
|
apiDoubleHeaders(),
|
|
cookieParser(),
|
|
bodyParser.text({ type: '*/*' }),
|
|
controller().serve,
|
|
].reduce(function(app, item) {
|
|
return app.use(item);
|
|
}, server.app);
|
|
},
|
|
contentFor: function(type, config) {
|
|
const vars = {
|
|
appName: config.modulePrefix,
|
|
environment: config.environment,
|
|
rootURL: config.environment === 'production' ? '{{.ContentPath}}' : config.rootURL,
|
|
config: config,
|
|
};
|
|
switch (type) {
|
|
case 'head':
|
|
return require('./templates/head.html.js')(vars);
|
|
case 'body':
|
|
return require('./templates/body.html.js')(vars);
|
|
case 'root-class':
|
|
return 'ember-loading';
|
|
}
|
|
},
|
|
};
|