generated from Arquisoft/lomap_0
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EXTRA: Trying to use npm build and getting green locks
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |