node.js - Using letsencrypt with Node Express application -


i'm trying make switch https application. want use letsencrypt, tutorials i've seen online states requires separate agent setup, renew certificate @ constant intervals. found greenlock-express seems bake renewal process https wrapping of express application, not need setup separate server acting renewal agent (or have misunderstood purpose?).

this have far:

// express import * http 'http'; import * https 'https'; import * e 'express'; const lex = require('greenlock-express');  /** run using myserver.initialize(process.argv) **/ export class myserver {   public app: e.express;   private clientpath = path.join(__dirname, './public');    static initialize(args: string[]): promise<any> {     return new myserver()       .start(args)       .catch((error: any) => console.error(error);   }    constructor() { }    start(args: string[]): promise<https.server> {     // simplified code here, in order display relevant info     return promise.resolve(this.createserver());   }    public createserver(): https.server {     this.app = e(); // creates express application      // setup routes , standard stuff, removed keep question simple      // setup base route else     this.app.get('/*', (req: e.request, res: e.response) => {       res.sendfile(path.resolve(this.clientpath, 'index.html'));     }); 

now, if return following here, app starts fine , responds http://localhost.

    return this.app.listen(80)       .on('listening', () => console.log(`serving on http://localhost/`)); 

but if instead try wrap greenlock-express thingy around app (this example given @ https://www.npmjs.com/package/greenlock-express, i'm bit disappointed not work out of box):

    const lex = lex.create({       server: 'staging',       email: 'my.email@mailprovider.com',       agreetos: true,       configdir: 'cert/',       approvedomains: ['mydomain.org']     });      // force redirect https     http.createserver(lex.middleware(require('redirect-https')())).listen(80, function () {       console.log('listening acme http-01 challenges on', this.address());     });      return <https.server> https.createserver(lex.httpsoptions, lex.middleware(this.app))       .listen(443, () => console.log(`serving on http://localhost/`));   } } 

nothing works. redirected http://localhost https://localhost, after that, browser gives , states the site cannot reached.

why? have misunderstood something?

edit

i aware letsencrypt might have issues resolving localhost my domain. have domain application, don't want deploy i'm not 100% sure works. want application runnable , testable localhost. that's thought

server: 'staging' 

part of greenlock-express config for.

yeah, think have. letsencrypt provide free, short-term, verified ssl certificates domains , subdomains (up limit of 10, believe). trying letsencrypt servers make request application @ http://localhost/.well-known/acme-challenge verify own domain. lets encrypt never resolve http://localhost server. need run code , module on server reachable public internet on domain own. letsencrypt able reach app, verify domain, , issue certificate. site run under ssl. that, or have misuderstood something!


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -