diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index 492ee583..4a1d02de 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -6,6 +6,9 @@ services: - "5000:5000" webapp: image: ghcr.io/arquisoft/lomap_en3a/webapp:latest + volumes: + - /etc/letsencrypt/live/lomapen3a.cloudns.ph/privkey.pem:/app/claves/privkey.pem + - /etc/letsencrypt/live/lomapen3a.cloudns.ph/fullchain.pem:/app/claves/fullchain.pem ports: - "443:443" depends_on: diff --git a/webapp/Dockerfile b/webapp/Dockerfile index d9033b5f..3cd26560 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -9,8 +9,8 @@ ARG API_URI="http://localhost:5000/api" ENV REACT_APP_API_URI=$API_URI #Create an optimized version of the webapp -#RUN npm run build +RUN npm run build #Execute npm run prod to run the server #CMD [ "npm", "run", "prod" ] -CMD ["npm", "start"] \ No newline at end of file +CMD node server.js \ No newline at end of file diff --git a/webapp/server.js b/webapp/server.js new file mode 100644 index 00000000..ef223f06 --- /dev/null +++ b/webapp/server.js @@ -0,0 +1,34 @@ +var fs = require('fs'); +var https = require('https'); +const express = require('express'); +var expressStaticGzip = require('express-static-gzip'); +const path = require('path'); + +//Load certificates +var privateKey = fs.readFileSync('claves/privkey.pem'); +var certificate = fs.readFileSync('claves/fullchain.pem'); +var credentials = {key: privateKey, cert: certificate}; + +var app = express(); + +//This will make sure that we will serve everything through https +app.all('*', function(req, res, next){ + if (req.secure) { + return next(); + } + res.redirect('https://'+req.hostname + req.url); +}); + +//Base path of our application. We serve first the brotli version (compression). +app.use('/', expressStaticGzip('build', { + enableBrotli: true, + orderPreference: ['br'] +})); + +//For react routes to work, fallback to index.html +app.get('*', (req, res) => { + res.sendFile(path.resolve(__dirname, 'build', 'index.html')); +}); + +var httpsServer = https.createServer(credentials, app); +httpsServer.listen(443); \ No newline at end of file