Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Update to use express for heroku reviews app #326

Merged
merged 15 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm run start:express
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"version": "0.1.0",
"description": "terra-core",
"engines": {
"node": "6.9.4"
},
"node": "6.9.4"
},
"repository": {
"type": "git",
"url": "git+https://github.com/cerner/terra-core.git"
Expand Down Expand Up @@ -42,6 +42,7 @@
"clean:install": "npm run clean:all && npm install",
"clean:obsolete-snapshots": "npm test -- -u",
"compile": "lerna run compile",
"compile:prod": "cd packages/terra-site && npm run compile:prod",
"deploy": "lerna run --scope terra-site deploy",
"heroku-prebuild": "npm install -g [email protected]",
"heroku-postbuild": "npm install --only=dev",
Expand All @@ -54,6 +55,7 @@
"pretest": "npm run lint",
"postinstall": "npm run bootstrap",
"start": "cd packages/terra-site && npm run start",
"start:express": "node scripts/express/app.js",
"test": "npm run jest && npm run test:nightwatch-default",
"test:nightwatch-default": "node ./packages/terra-toolkit/lib/scripts/nightwatch-process.js --env default-tiny,default-small,default-medium,default-large,default-huge,default-enormous"
},
Expand All @@ -72,6 +74,7 @@
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.9.0",
"express": "^4.15.2",
"glob": "^7.1.1",
"husky": "^0.13.1",
"identity-obj-proxy": "^3.0.0",
Expand Down
29 changes: 29 additions & 0 deletions scripts/express/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console */
const express = require('express');
const path = require('path');
const shell = require('shelljs');

const app = express();
const port = process.env.PORT || 8081;
// npm script to build assets by webpack
const buildCommand = 'npm run compile:prod';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want to build out our review apps with a dev environment so we get the additional warnings. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I'm fine with dev environment with production webpack. As webpack will eat a lot of memories, more dev features will make reviews app more unstable. I'd like to add more features if we can reduce the memory cost with webpack compile.

// path to webpack built path
const buildPath = path.join(__dirname, '../../packages/terra-site/build');

// listen to PORT to avoid Heroku error: R10 boot timeout
app.listen(port);
console.log(`Listening ${port}`);

if (!shell.test('-d', buildPath)) {
if (shell.exec(buildCommand).code !== 0) {
console.log(`Errors in command: ${buildCommand}`);
process.exit(1);
} else {
console.log(`Finished command: ${buildCommand}`);
}
}

app.use('/static', express.static(buildPath));
app.get('/', (req, res) => res.redirect('/static'));
console.log('Switched to built assets.');