HTTPS Feature is not working in Koop JS

1529
2
Jump to solution
06-17-2021 12:03 PM
PrasanthRamachandran2
New Contributor II

Hi,

I have developed an app with Koop JS and created a custom provider. Everything is working however the URL workings only on HTTP. So, I have created PEM files for SSL and CA certificates and placed them in the app folder. Then run the 'Koop Serve' command with SSL Cert and SSL key attributes. However, the link works on HTTP, not on HTTPS. So, to make sure there is no issue with the certificate, I have created a simple NODE JS app with an HTTPS node js module. Everything is working fine with CA and SSL certificate files.

So, just wanted to see if I am missing anything here to get HTTPS working on Koop JS applications. Below links are I used as a reference. Let me know if you want me to share any screenshots or code files for this issue.

https://koopjs.github.io/blog/2021/01/19/koop-cli-v1-1-0-release/

https://nodejs.org/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server/

Creating an issue in github as well (https://github.com/koopjs/koop/issues/376).

Tagging @AlexanderHarris to get help.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KC
by
Occasional Contributor

I also couldn't get the HTTPS server up per the https://nodejs.org/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server/ instructions.  But I got things working with the following:

  • I modified app/src/index.js...
    • Add in the following constants after the first chunk of constants:
      • const fs = require('fs-extra')
        const https = require('https')
    • Comment out the last line (koop.server.listen..) and put in the following in its place:
      • https.createServer(
        {
        key: fs.readFileSync('key.pem'),
        cert: fs.readFileSync('cert.pem')
        },
        koop.server
        ).listen(config.port, () => {
        koop.log.info(`Server listening at https://localhost:${config.port}`)
        })
  • I placed my key.pem and cert.pem in the app folder where I would be calling the koop serve  (don't need to add any parameters) command from.

I think that's it, hope it helps..

View solution in original post

2 Replies
KC
by
Occasional Contributor

I also couldn't get the HTTPS server up per the https://nodejs.org/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server/ instructions.  But I got things working with the following:

  • I modified app/src/index.js...
    • Add in the following constants after the first chunk of constants:
      • const fs = require('fs-extra')
        const https = require('https')
    • Comment out the last line (koop.server.listen..) and put in the following in its place:
      • https.createServer(
        {
        key: fs.readFileSync('key.pem'),
        cert: fs.readFileSync('cert.pem')
        },
        koop.server
        ).listen(config.port, () => {
        koop.log.info(`Server listening at https://localhost:${config.port}`)
        })
  • I placed my key.pem and cert.pem in the app folder where I would be calling the koop serve  (don't need to add any parameters) command from.

I think that's it, hope it helps..

PrasanthRamachandran2
New Contributor II

Thank you KC! This solution has worked for me!

0 Kudos