From 180cb8cc8cbb77d8f9b0fb5b87ac5787d81c1c3b Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 8 Feb 2016 18:34:43 +0100 Subject: [PATCH] add express js server for production --- Dockerfile | 10 ++++++++++ README.md | 4 ++-- package.json | 6 ++++-- server.js | 12 ++++++++++++ webpack.config.js | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100644 server.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1e18227 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM node:argon + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +ONBUILD COPY package.json /usr/src/app/ +ONBUILD RUN npm install +ONBUILD COPY . /usr/src/app + +CMD [ "npm", "start" ] \ No newline at end of file diff --git a/README.md b/README.md index 7816925..bcd1e9c 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ move inside lesspass folder start application - npm start + npm run dev open the application in a browser: [http://localhost:8080](http://localhost:8080) @@ -39,4 +39,4 @@ run test in watch mode ## build for production - npm run build \ No newline at end of file + npm start \ No newline at end of file diff --git a/package.json b/package.json index 45d70f6..a19a161 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,10 @@ "test": "mocha --compilers js:babel-core/register tests", "test:watch": "npm run test -- -w", "prestart": "npm install", - "start": "webpack-dev-server --inline --hot --host 0.0.0.0", + "dev": "webpack-dev-server --inline --hot --host 0.0.0.0", "prebuild": "rimraf dist && npm prune", - "build": "NODE_ENV=production webpack --progress --hide-modules" + "build": "NODE_ENV=production webpack --progress --hide-modules", + "start": "npm run build && NODE_ENV=production node server.js" }, "repository": { "type": "git", @@ -28,6 +29,7 @@ "dependencies": { "bootstrap": "^4.0.0-alpha.2", "clipboard": "^1.5.5", + "express": "^4.13.4", "font-awesome": "^4.5.0", "jquery": "^2.2.0", "tether": "^1.1.1", diff --git a/server.js b/server.js new file mode 100644 index 0000000..d480958 --- /dev/null +++ b/server.js @@ -0,0 +1,12 @@ +var express = require('express'); +var app = express(); + +app.use('/dist', express.static(__dirname + '/dist')); + +app.get('*', function (req, res) { + res.sendFile(__dirname + '/index.html'); +}); + +app.listen(8080, function () { + console.log('LessPass frontend listening on port 8080'); +}); diff --git a/webpack.config.js b/webpack.config.js index ba9714f..8e94385 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,7 @@ var webpack = require('webpack'); module.exports = { - entry: './app/main.js', + entry: ['./app/main.js'], output: { path: './dist', publicPath: '/dist/',