Skip to content

Commit

Permalink
EXTRA: Trying to use npm build and getting green locks
Browse files Browse the repository at this point in the history
  • Loading branch information
uo282892 committed Apr 27, 2023
1 parent af5cfdf commit cedbfe9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docker-compose-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions webapp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
CMD node server.js
34 changes: 34 additions & 0 deletions webapp/server.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit cedbfe9

Please sign in to comment.