Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add umi-plugin-datahub #415

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/af-webpack/src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ process.env.NODE_ENV = 'development';
export default function dev({
webpackConfig,
extraMiddlewares,
beforeServerWithApp,
beforeServer,
afterServer,
onCompileDone = noop,
Expand Down Expand Up @@ -75,9 +76,12 @@ export default function dev({
overlay: false,
host: HOST,
proxy,
https: process.env.HTTPS ? true : false,
https: !!process.env.HTTPS,
contentBase: process.env.CONTENT_BASE,
before(app) {
if (beforeServerWithApp) {
beforeServerWithApp(app);
}
if (extraMiddlewares) {
extraMiddlewares.forEach(middleware => {
app.use(middleware);
Expand Down
7 changes: 7 additions & 0 deletions packages/umi-build-dev/src/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ export default class Service {
// eslint-disable-line
webpackConfig,
extraMiddlewares,
beforeServerWithApp: app => {
this.applyPlugins('beforeServerWithApp', {
args: {
app,
},
});
},
beforeServer: devServer => {
this.applyPlugins('beforeServer', {
args: {
Expand Down
24 changes: 24 additions & 0 deletions packages/umi-plugin-datahub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "umi-plugin-datahub",
"version": "0.0.1",
"main": "./lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-datahub"
},
"homepage": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-datahub",
"authors": [
"chencheng <[email protected]> (https://github.com/sorrycc)"
],
"bugs": {
"url": "https://github.com/umijs/umi/issues"
},
"files": [
"lib",
"src"
],
"dependencies": {
"datahub-proxy-middleware": "^1.0.9",
"macaca-datahub": "^1.0.51"
}
}
28 changes: 28 additions & 0 deletions packages/umi-plugin-datahub/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { join } from 'path';
import DataHub from 'macaca-datahub';
import datahubMiddleware from 'datahub-proxy-middleware';

const datahubConfig = {
port: 5678,
hostname: '127.0.0.1',
store: join(__dirname, 'data'),
proxy: {
'^/api': {
hub: 'ifccustmng',
},
},
showBoard: false,
};

const defaultDatahub = new DataHub({
port: datahubConfig.port,
});

export default api => {
api.register('beforeServerWithApp', ({ args: { app } }) => {
datahubMiddleware(app)(datahubConfig);
defaultDatahub.startServer(datahubConfig).then(() => {
console.log('datahub ready');
});
});
};