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

separate into npm module and example project #626

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
09229a5
update paths to npm module
bdefore Nov 26, 2015
1cdb2ac
working with npm module
bdefore Nov 26, 2015
126dd9e
point to new external source
bdefore Nov 26, 2015
e6bbd1b
add static path
bdefore Nov 26, 2015
0ac38ef
update to unconfigured api
bdefore Nov 26, 2015
7d86dc5
fix npm lint
bdefore Nov 26, 2015
58acb59
update version
bdefore Nov 26, 2015
652263e
remove some dependencies that are now handled by redux-universal-test
bdefore Nov 26, 2015
c1623f1
return bootstrap config settings, no longer an issue
bdefore Nov 26, 2015
6a8d6e9
update to latest on npm
bdefore Nov 26, 2015
c72c33d
webpack is not needed by this repo anymore directly
bdefore Nov 26, 2015
f8afc25
remove some more unneeded deps
bdefore Nov 26, 2015
dde48b3
all of these are devDependencies now
bdefore Nov 26, 2015
e7c628f
not sure how the NODE_ENV got lost here
bdefore Nov 26, 2015
197522b
update to latest npm module
bdefore Nov 27, 2015
de1b8c4
forgot to put Home back in
bdefore Nov 27, 2015
e7f316a
update to new version of npm module, without example code in it
bdefore Nov 27, 2015
9e9fe66
use npm module bins instead
bdefore Nov 27, 2015
7e45218
update to latest npm module
bdefore Nov 27, 2015
a6dba3e
update to 0.4.0 of npm module which removes example api actions, we n…
bdefore Nov 27, 2015
86c8044
remove unrelated test, rename dep to redux-universal-starter
bdefore Nov 27, 2015
8449048
merge in master
bdefore Nov 27, 2015
798e7cc
update to newest npm module and fix karma tests
bdefore Nov 28, 2015
16815ee
remove obselete test-node configuration in travis
bdefore Nov 28, 2015
948b611
update to 0.11.0 which allows custom isomorphic tools configuration
bdefore Nov 29, 2015
9ac9218
update to latest
bdefore Nov 29, 2015
08483f1
trigger another travis build
bdefore Nov 29, 2015
0d1f7c5
fix linting errors from carried-over isomorphic tools config
bdefore Nov 29, 2015
916d1b9
verbose logging
bdefore Dec 1, 2015
ad1a3d5
pass correct bootstrap config on production, fix serverside renders n…
bdefore Dec 1, 2015
fa68c1a
update to latest npm module
bdefore Dec 1, 2015
fd2962f
update to new module name, add url-loader as it is a peer dependency …
bdefore Dec 1, 2015
2479a3d
update latest changes from react-redux-universal-hot-example repo
bdefore Dec 1, 2015
81435f1
merge in master
bdefore Dec 1, 2015
e5df1f5
remove old logs
bdefore Dec 1, 2015
c3fc59d
enable socket io
bdefore Dec 2, 2015
cf597ca
drop back to redux router beta4
bdefore Dec 2, 2015
ff34e08
bump npm module version
bdefore Dec 2, 2015
6059438
update to latest and provide npm script for easier development of uni…
bdefore Dec 2, 2015
5ac0d49
bump version, builds paths to reducers smarter
bdefore Dec 2, 2015
a7fcd08
update to latest npm module, add api to dev-universal script
bdefore Dec 3, 2015
73bc07a
update to new configuration structure
bdefore Dec 3, 2015
e52ed71
midway through removing need for config alias
bdefore Dec 3, 2015
3b7a78a
update to streamlined npm module config
bdefore Dec 3, 2015
7ee068e
move api back to example project
bdefore Dec 5, 2015
2901d26
add back test-node script to travis
bdefore Dec 5, 2015
b3f60fa
update to new npm module. ApiClient is now fetcher.js and a redux mid…
bdefore Dec 7, 2015
3ca5f0f
fixes build issue on deploys
bdefore Dec 7, 2015
462a309
missed dependency
bdefore Dec 7, 2015
012e864
explicitly require npm 3
bdefore Dec 7, 2015
4ea989d
revert previous and import properly in production
bdefore Dec 7, 2015
16f43aa
add socket io import
bdefore Dec 7, 2015
50e6112
update to latest universal-redux package
bdefore Dec 13, 2015
f5f8e7b
update to universal-redux 0.17.1
bdefore Dec 14, 2015
f338475
remove check for universal existence
bdefore Dec 14, 2015
9b7b5dc
add mocha explicitly as a dependency
bdefore Dec 20, 2015
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
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ "extends": "eslint-config-airbnb",
{
"extends": "eslint-config-airbnb",
"env": {
"browser": true,
"node": true,
Expand Down Expand Up @@ -36,6 +37,10 @@
"__SERVER__": true,
"__DISABLE_SSR__": true,
"__DEVTOOLS__": true,
"__META__": {},
"__API_ENDPOINT__": '',
"__API_HOST__": '',
"__API_PORT__": '',
"socket": true,
"webpackIsomorphicTools": true
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist/
webpack-assets.json
webpack-stats.json
npm-debug.log
.DS_Store
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ before_script:
script:
- npm run lint
- npm test
- npm run test-node
- npm test-node
15 changes: 7 additions & 8 deletions api/api.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import express from 'express';
import session from 'express-session';
import bodyParser from 'body-parser';
import config from '../src/config';
import * as actions from './actions/index';
import {mapUrl} from 'utils/url.js';
import PrettyError from 'pretty-error';
import http from 'http';
import SocketIo from 'socket.io';

const apiPort = process.env.APIPORT;
const apiHost = process.env.APIHOST || 'localhost';

const pretty = new PrettyError();
const app = express();

Expand All @@ -24,9 +26,7 @@ app.use(session({
}));
app.use(bodyParser.json());


app.use((req, res) => {

const splittedUrlPath = req.url.split('?')[0].split('/').slice(1);

const {action, params} = mapUrl(actions, splittedUrlPath);
Expand Down Expand Up @@ -57,13 +57,13 @@ const bufferSize = 100;
const messageBuffer = new Array(bufferSize);
let messageIndex = 0;

if (config.apiPort) {
const runnable = app.listen(config.apiPort, (err) => {
if (apiPort) {
const runnable = app.listen(apiPort, (err) => {
if (err) {
console.error(err);
}
console.info('----\n==> 🌎 API is running on port %s', config.apiPort);
console.info('==> 💻 Send requests to http://%s:%s', config.apiHost, config.apiPort);
console.info('----\n==> 🌎 API is running on port %s', apiPort);
console.info('==> 💻 Send requests to http://%s:%s', apiHost, apiPort);
});

io.on('connection', (socket) => {
Expand All @@ -87,7 +87,6 @@ if (config.apiPort) {
});
});
io.listen(runnable);

} else {
console.error('==> ERROR: No PORT environment variable has been specified');
}
1 change: 0 additions & 1 deletion api/utils/url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export function mapUrl(availableActions = {}, url = []) {

const notFound = {action: null, params: []};

// test for empty input
Expand Down
28 changes: 0 additions & 28 deletions bin/server.js

This file was deleted.

3 changes: 3 additions & 0 deletions bin/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
require('../server.babel'); // babel registration (runtime transpilation for node)
require('./start_es6.js');
60 changes: 60 additions & 0 deletions bin/start_es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env node
import path from 'path';
import http from 'http';
import renderer from 'universal-redux';
import httpProxy from 'http-proxy';
import config from '../config/universal-redux.config.js';
import SocketIo from 'socket.io';

const isProduction = process.env.NODE_ENV !== 'production';
const apiPort = process.env.APIPORT;
const apiHost = process.env.APIHOST || 'localhost';
const apiEndpoint = '/api';

function setupProxy(app) {

const proxy = httpProxy.createProxyServer({
target: 'http://' + apiHost + ':' + apiPort,
ws: true
});

// Proxy to API server
app.use(`${apiEndpoint}`, (req, res) => {
proxy.web(req, res);
});

// added the error handling to avoid https://github.com/nodejitsu/node-http-proxy/issues/527
proxy.on('error', (error, req, res) => {
let json;
if (error.code !== 'ECONNRESET') {
console.error('proxy error', error);
}
if (!res.headersSent) {
res.writeHead(500, {'content-type': 'application/json'});
}

json = {error: 'proxy_error', reason: error.message};
res.end(JSON.stringify(json));
});
}

const app = renderer.app();

setupProxy(app);

renderer.setup(config);

const server = new http.Server(app);

if (!isProduction) {
const io = new SocketIo(server);
io.path(`${__API_ENDPOINT__}/ws`);
}

server.listen(config.server.port, (err) => {
if (err) {
console.error(err);
}
console.info('==> 🌎 API calls will be received at:', config.server.host + ':' + config.server.port + apiEndpoint);
console.info('==> 💻 Open http://localhost:%s in a browser to view the app.', config.server.port);
});
22 changes: 22 additions & 0 deletions config/meta.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
title: 'React Redux Example',
description: 'All the modern best practices in one example.',
meta: {
charSet: 'utf-8',
property: {
'og:site_name': 'React Redux Example',
'og:image': 'https://react-redux.herokuapp.com/logo.jpg',
'og:locale': 'en_US',
'og:title': 'React Redux Example',
'og:description': 'All the modern best practices in one example.',
'twitter:card': 'summary',
'twitter:site': '@erikras',
'twitter:creator': '@erikras',
'twitter:title': 'React Redux Example',
'twitter:description': 'All the modern best practices in one example.',
'twitter:image': 'https://react-redux.herokuapp.com/logo.jpg',
'twitter:image:width': '200',
'twitter:image:height': '200'
}
}
}
184 changes: 184 additions & 0 deletions config/universal-redux.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/* eslint-disable */
const path = require('path');
const isProduction = process.env.NODE_ENV === 'production';
const projectRoot = path.resolve(__dirname, '..');
const sourceRoot = path.resolve(__dirname, '../src');
const apiPort = process.env.APIPORT;
const apiHost = process.env.APIHOST || 'localhost';
const meta = require('./meta.config.js');

module.exports = Object.assign({

/*
// Express configuration
*/
server: {
/*
// The host to run the Express universal renderer. See src/server.js.
//
// Expects: String
*/
host: process.env.HOST || 'localhost',

/*
// The port to run Express universal renderer will run on. See src/server.js.
//
// Expects: Number
*/
port: process.env.PORT,
},

/*
// Globals available to both serverside and clientside rendering.
// You may also add your own here.
*/
globals: {

/*
// Whether or not to run redux-logger
//
// Expects: Boolean
*/
__LOGGER__: false,

/*
// Whether or not to run redux-devtools
//
// Expects: Boolean
*/
__DEVTOOLS__: !isProduction,

__API_ENDPOINT__: '/api',
__API_PORT__: apiPort,
__API_HOST__: apiHost,
__META__: meta
},

/*
// Enable eslint checks per Webpack build. Will not be run
// on production.
//
// Expects: Boolean
*/
lint: {
enabled: true,
config: projectRoot + '/.eslintrc'
},

/*
// Enable native desktop notifications for Webpack build events.
// Will not be run on production.
//
// Expects: Boolean
*/
notifications: false,

/*
// Path to a file with customizations for the default
// webpack-isomorphic-tools configuration. Optional.
//
// Expects: String
*/
toolsConfigPath: __dirname + '/webpack-isomorphic-tools.config.js',

/*
// When eneabled, will output Webpack and Webpack Isomorphic
// Tools configurations at startup
//
// Expects: Boolean
*/
verbose: true,

/*
// The react-router Routes file, Required. Will be added to Webpack aliases.
*/
routes: sourceRoot + '/routes.js',

redux: {
/*
// The path to the index of your Redux reducers. Required. Will be added
// to Webpcak aliases.
*/
reducers: sourceRoot + '/redux/modules/reducer.js',

/*
// A path to an index of middleware functions. On the serverside, these will
// be called with the Express request and response. Optional.
//
// Expects: String
*/
middleware: sourceRoot + '/redux/middleware/index.js'
},

/*
// The path to your replacement for the default HTML shell. Optional.
// If not provided, the default used will be that in src/helpers/Html.js.
// Will be added to Webpack aliases.
*/
// htmlShell: sourceRoot + '/helpers/Html.js',

webpack: {

/*
// Whether to merge into the default webpack configuration using
// webpack-config-merger.
//
// If the `merge` parameter is `true`, properties with the same name
// will be overwritten. Arrays will be concatenated. Objects will
// be merged.
//
// If the `merge` parameter is `false`, default webpack settings
// will not be used and the config specified here will need to
// be the complete settings required for building.
*/
merge: true,

/*
// Webpack configuration cusomtizations. There are more parameters
// available than specified here. For the full list, see
// https://webpack.github.io/docs/configuration.html.
*/
config: {

/*
// The Webpack devtool configuration. May affect build times.
// See https://webpack.github.io/docs/configuration.html#devtool
*/
devtool: 'inline-eval-cheap-source-map',

entry: {
main: [
'bootstrap-sass!' + sourceRoot + '/theme/bootstrap.config' + (isProduction ? '.prod' : '') + '.js',
'font-awesome-webpack!' + sourceRoot + '/theme/font-awesome.config' + (isProduction ? '.prod' : '') + '.js'
]
},

/*
// Not recommended to change.
*/
context: projectRoot,

/*
// Not recommended to change.
*/
output: {

/*
// Not recommended to change.
*/
path: projectRoot + '/static/dist'

},

resolve: {

/*
// Not recommended to change.
*/
root: sourceRoot
}
}
}

});
/* eslint-enable */
Loading