0

I can get bitbucket to run at localhost:7990 just fine however I wanted to secure it with a SSL and also remove the port from the address. When I attempt to do this with the code below and my node server I just simply get the 'CANNOT GET /' error if I goto https://example.com. Even though the bitbucket app is running.

// Dependencies
const fs = require('fs');
const path = require('path');
const http = require('http');
const https = require('https');
const express = require('express');
const express_force_ssl = require('express-force-ssl');
const app = express();

// Certificate
const privateKey = fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem', 'utf8');
const certificate = fs.readFileSync('/etc/letsencrypt/live/example.com/fullchain.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/example.com/chain.pem', 'utf8');

const credentials = {
    key: privateKey,
    cert: certificate,
    ca: ca
};
app.use(express_force_ssl);

// Load main application
app.use(express.static(path.join(__dirname, '../../var/www/bitbucket/')));

// Starting both http & https servers
const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);

httpServer.listen(80, (req,res) => {
  console.log('HTTPS Server running on port 80');
});

httpsServer.listen(443, (req, res) => {
    console.log('HTTPS Server running on port 443');
}); 
Robert
  • 343
  • 6
  • 16
  • Bitbucket Server is a self-contained web app written in Java, and you can't serve it as a static directory from Express. You need to a reverse proxy to do what you want, which is best done by following Atlassian's recommendations here: https://confluence.atlassian.com/bitbucketserver/proxying-and-securing-bitbucket-server-776640099.html. If you really want to use Express to do it, perhaps look into the `express-http-proxy` NPM module. – Scott Dudley Apr 08 '20 at 19:57
  • Thanks yes I've tried the http-proxy and had no luck. I'm back to trying to make it work with Nginx! – Robert Apr 08 '20 at 22:59

0 Answers0