open-consul/ui/packages/consul-ui/lib/startup/index.js
John Cowen c98130cc08
ui: Move to Workspaced Structure (#8994)
* ui: Add the most basic workspace root in /ui

* We already have a LICENSE file in the repository root

* Change directory path in build scripts ui-v2 -> ui

* Make yarn install flags configurable from elsewhere

* Minimal workspace root makefile

* Call the new docker specific target

* Update yarn in the docker build image

* Reconfigure the netlify target and move to the higher makefile

* Move ui-v2 -> ui/packages/consul-ui

* Change repo root to refleect new folder structure

* Temporarily don't hoist consul-api-double

* Fixup CI configuration

* Fixup lint errors

* Fixup Netlify target
2020-10-21 15:23:16 +01:00

55 lines
1.7 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: see if we can move these into the project specific `/server` directory
// instead of inside an addon
// 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';
}
},
};