CategoriesUncategorized

Vue.js with RedHat Node Image — using Express Server

FROM registry.redhat.io/ubi8/nodejs-10:latest

LABEL maintainer="Joseph Shinaberry <joseph.shinaberry@spathesystems.com>"

WORKDIR /app

COPY . /app

USER root

RUN yum install npm \
    python2 -y && \
    cd /app && \
    npm install --unsafe-perm && \
    npm run build && \
    chown -R 1001:0 /app

USER 1001

EXPOSE 8080

CMD [ "node", "server.js" ]

Add this into the package.json under dependencies.

        "connect-history-api-fallback": "^1.6.0",
        "express": "^4.15.2",

Create server.js file in project root and add the following code:

const express = require('express');
const path = require('path');
const history = require('connect-history-api-fallback');

const app = express();

const staticFileMiddleware = express.static(path.join(__dirname + '/dist'));

app.use(staticFileMiddleware);
app.use(history({
  disableDotRule: true,
  verbose: true
}));
app.use(staticFileMiddleware);

app.get('/', function (req, res) {
  res.render(path.join(__dirname + '/dist/index.html'));
});

var server = app.listen(process.env.PORT || 8080, function () {
  var port = server.address().port;
  console.log("App now running on port", port);
});

Leave a Reply

Your email address will not be published. Required fields are marked *