Skip to content

Commit

Permalink
added server-side babel require hook
Browse files Browse the repository at this point in the history
  • Loading branch information
pheuter committed Feb 28, 2016
1 parent 8a4cabb commit 9bdb23f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Major refactor to bring dependencies up-to-date:
- Upgrade Babel 5 -> 6
- Replace Karma and Istanbul with ava and nyc
- No more custom routers
- Added server-side Babel require hook


# v0.3.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/main.js",
"scripts": {
"postinstall": "npm run build",
"server": "node server.js",
"server": "node start.js",
"build": "webpack -p --progress --config webpack.production.config.js",
"test": "nyc ava --fail-fast --verbose --require babel-register",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
Expand Down
12 changes: 6 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const express = require('express');
import express from 'express';
const app = express();


Expand All @@ -12,7 +12,7 @@ const app = express();
************************************************************/

// Serve application file depending on environment
app.get('/app.js', function(req, res) {
app.get('/app.js', (req, res) => {
if (process.env.PRODUCTION) {
res.sendFile(__dirname + '/build/app.js');
} else {
Expand All @@ -21,7 +21,7 @@ app.get('/app.js', function(req, res) {
});

// Serve aggregate stylesheet depending on environment
app.get('/style.css', function(req, res) {
app.get('/style.css', (req, res) => {
if (process.env.PRODUCTION) {
res.sendFile(__dirname + '/build/style.css');
} else {
Expand All @@ -30,7 +30,7 @@ app.get('/style.css', function(req, res) {
});

// Serve index page
app.get('*', function(req, res) {
app.get('*', (req, res) => {
res.sendFile(__dirname + '/build/index.html');
});

Expand All @@ -53,7 +53,7 @@ if (!process.env.PRODUCTION) {
hot: true,
noInfo: true,
historyApiFallback: true
}).listen(9090, 'localhost', function (err, result) {
}).listen(9090, 'localhost', (err, result) => {
if (err) {
console.log(err);
}
Expand All @@ -68,7 +68,7 @@ if (!process.env.PRODUCTION) {
*****************/

const port = process.env.PORT || 8080;
const server = app.listen(port, function () {
const server = app.listen(port, () => {
const host = server.address().address;
const port = server.address().port;

Expand Down
5 changes: 5 additions & 0 deletions start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Server-side entrypoint that registers Babel's require() hook
const babelRegister = require('babel-register');
babelRegister();

require('./server');

0 comments on commit 9bdb23f

Please sign in to comment.