Merge pull request #24 from mozilla/directory-restructure
Directory restructure
This commit is contained in:
Коммит
5eb8bc1573
|
@ -2,8 +2,9 @@
|
|||
|
||||
require('../server.babel');
|
||||
|
||||
const server = require('../src/server').default;
|
||||
const config = require('../config').default;
|
||||
const appName = config.get('currentApp');
|
||||
const server = require(`../src/${appName}/server`).default;
|
||||
|
||||
const port = config.get('serverPort');
|
||||
const host = config.get('serverHost');
|
||||
|
|
|
@ -16,4 +16,11 @@ config.set('serverPort', process.env.NODE_PORT || 4000);
|
|||
config.set('webpackHost', process.env.NODE_HOST || '127.0.0.1');
|
||||
config.set('webpackPort', 3000);
|
||||
|
||||
const APP_NAMES = ['search', 'disco'];
|
||||
if (APP_NAMES.indexOf(process.env.APP_NAME) < 0) {
|
||||
config.set('currentApp', 'core');
|
||||
} else {
|
||||
config.set('currentApp', process.env.APP_NAME);
|
||||
}
|
||||
|
||||
export default config;
|
||||
|
|
|
@ -8,13 +8,14 @@ const WEBPACK_HOST = config.get('webpackHost');
|
|||
const WEBPACK_PORT = config.get('webpackPort');
|
||||
const SERVER_HOST = config.get('serverHost');
|
||||
const SERVER_PORT = config.get('serverPort');
|
||||
const APP_NAME = config.get('currentApp');
|
||||
|
||||
// Note: Object.assign only goes one level deep.
|
||||
export default Object.assign({}, prodWebpackConfig, {
|
||||
entry: [
|
||||
`webpack-dev-server/client?http://${WEBPACK_HOST}:${WEBPACK_PORT}/`,
|
||||
'webpack/hot/only-dev-server',
|
||||
'./src/client',
|
||||
`./src/${APP_NAME}/client`,
|
||||
],
|
||||
output: {
|
||||
path: path.join(__dirname, '../dist'),
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
"scripts": {
|
||||
"start": "bin/server.js",
|
||||
"dev": "npm run start & webpack-dev-server --progress --color --port 3000",
|
||||
"dev:search": "APP_NAME=search npm run dev",
|
||||
"dev:disco": "APP_NAME=disco npm run dev",
|
||||
"test": "npm run test:lint && npm run test:style",
|
||||
"test:lint": "eslint .",
|
||||
"test:style": "jscs .",
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
import createLocation from 'history/lib/createLocation';
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
import React from 'react';
|
||||
|
||||
import { renderToString } from 'react-dom/server';
|
||||
import { RouterContext, match } from 'react-router';
|
||||
|
||||
export default function (routes) {
|
||||
const app = express();
|
||||
|
||||
app.use(express.static(path.join(__dirname, '../dist')));
|
||||
|
||||
app.use((req, res) => {
|
||||
const location = createLocation(req.url);
|
||||
|
||||
match({ routes, location }, (err, redirectLocation, renderProps) => {
|
||||
if (err) {
|
||||
console.error(err); // eslint-disable-line no-console
|
||||
return res.status(500).end('Internal server error');
|
||||
}
|
||||
|
||||
if (!renderProps) return res.status(404).end('Not found.');
|
||||
|
||||
const InitialComponent = (
|
||||
<RouterContext {...renderProps} />
|
||||
);
|
||||
|
||||
const componentHTML = renderToString(InitialComponent);
|
||||
|
||||
const HTML = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Isomorphic Redux Demo</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="react-view">${componentHTML}</div>
|
||||
<script type="application/javascript" src="/bundle.js"></script>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
return res.end(HTML);
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
|
@ -2,7 +2,7 @@ import React from 'react';
|
|||
import { render } from 'react-dom';
|
||||
import { Router } from 'react-router';
|
||||
import createBrowserHistory from 'history/lib/createBrowserHistory';
|
||||
import routes from 'routes';
|
||||
import routes from './routes';
|
||||
|
||||
const history = createBrowserHistory();
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import React from 'react';
|
||||
import { Route } from 'react-router';
|
||||
|
||||
import discoRoutes from '../disco/routes';
|
||||
import searchRoutes from '../search/routes';
|
||||
|
||||
export default (
|
||||
<Route children={[discoRoutes, searchRoutes]} />
|
||||
);
|
|
@ -0,0 +1,7 @@
|
|||
import baseServer from './baseServer';
|
||||
|
||||
import routes from './routes';
|
||||
|
||||
const app = baseServer(routes);
|
||||
export default app;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import { Router } from 'react-router';
|
||||
import createBrowserHistory from 'history/lib/createBrowserHistory';
|
||||
import routes from './routes';
|
||||
|
||||
const history = createBrowserHistory();
|
||||
|
||||
render(
|
||||
<Router children={routes} history={history} />,
|
||||
document.getElementById('react-view')
|
||||
);
|
|
@ -4,7 +4,7 @@ export default class AppView extends React.Component {
|
|||
render() {
|
||||
return (
|
||||
<div id="app-view">
|
||||
<h1>HELLO WORLD</h1>
|
||||
<h1>HELLO DISCO WORLD</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
|
@ -4,5 +4,5 @@ import { Route } from 'react-router';
|
|||
import App from './components/hello-world';
|
||||
|
||||
export default (
|
||||
<Route name="app" component={App} path="/" />
|
||||
<Route name="disco" component={App} path="/disco" />
|
||||
);
|
|
@ -0,0 +1,7 @@
|
|||
import baseServer from '../core/baseServer';
|
||||
|
||||
import routes from './routes';
|
||||
|
||||
const app = baseServer(routes);
|
||||
export default app;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import { Router } from 'react-router';
|
||||
import createBrowserHistory from 'history/lib/createBrowserHistory';
|
||||
import routes from './routes';
|
||||
|
||||
const history = createBrowserHistory();
|
||||
|
||||
render(
|
||||
<Router children={routes} history={history} />,
|
||||
document.getElementById('react-view')
|
||||
);
|
|
@ -0,0 +1,11 @@
|
|||
import React from 'react';
|
||||
|
||||
export default class AppView extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div id="app-view">
|
||||
<h1>HELLO SEARCH WORLD</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import React from 'react';
|
||||
import { Route } from 'react-router';
|
||||
|
||||
import App from './components/hello-world';
|
||||
|
||||
export default (
|
||||
<Route name="search" component={App} path="/search" />
|
||||
);
|
|
@ -0,0 +1,7 @@
|
|||
import baseServer from '../core/baseServer';
|
||||
|
||||
import routes from './routes';
|
||||
|
||||
const app = baseServer(routes);
|
||||
export default app;
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
import createLocation from 'history/lib/createLocation';
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
import React from 'react';
|
||||
|
||||
import { renderToString } from 'react-dom/server';
|
||||
import { RouterContext, match } from 'react-router';
|
||||
|
||||
import routes from './routes';
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.static(path.join(__dirname, '../dist')));
|
||||
|
||||
app.use((req, res) => {
|
||||
const location = createLocation(req.url);
|
||||
|
||||
match({ routes, location }, (err, redirectLocation, renderProps) => {
|
||||
if (err) {
|
||||
console.error(err); // eslint-disable-line no-console
|
||||
return res.status(500).end('Internal server error');
|
||||
}
|
||||
|
||||
if (!renderProps) return res.status(404).end('Not found.');
|
||||
|
||||
const InitialComponent = (
|
||||
<RouterContext {...renderProps} />
|
||||
);
|
||||
|
||||
const componentHTML = renderToString(InitialComponent);
|
||||
|
||||
const HTML = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Isomorphic Redux Demo</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="react-view">${componentHTML}</div>
|
||||
<script type="application/javascript" src="/bundle.js"></script>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
return res.end(HTML);
|
||||
});
|
||||
});
|
||||
|
||||
export default app;
|
Загрузка…
Ссылка в новой задаче