Tayyab Sarwar
Tayyab Sarwar

Reputation: 101

greenlock-express: TypeError: greenlock.app is not a function

I am trying to run my Express.js with greenlock-express using this example:

https://git.coolaj86.com/coolaj86/greenlock-express.js/src/branch/master/examples/production.js

But I am getting these errors:

[:80] Handling ACME challenges and redirecting to http2 (spdy/h2)
[:443] Serving http2 (spdy/h2)

[error] [greenlock.app] Your HTTP handler had an uncaught error:

TypeError: greenlock.app is not a function
    at //node_modules/greenlock-express/index.js:64:23

Does anyone know why the example fails, and how I should fix it?

Upvotes: 0

Views: 817

Answers (1)

coolaj86
coolaj86

Reputation: 77074

I'm the author of greenlock and your problem is one of two things:

app must be a function

In your greenlock config you need to define app as function (req, res) { ... }

For example:

greenlock.create({
  ...
, app: function (req, res) {
    require('./my-express-app.js')(req, res);
  }
})

express app must be exported

var app = express();
...
module.exports = app;

watch (and follow) the video(s)

If you follow this verbatim you will have a working config and you will be able to change it from there:

https://www.youtube.com/watch?v=e8vaR4CEZ5s&list=PLZaEVINf2Bq_lrS-OOzTUJB4q3HxarlXk

error message

I tried to make the error message pretty clear:

TypeError: greenlock.app is not a function
    at //node_modules/greenlock-express/index.js:64:23

It makes sense to me, of course, but obviously not to you - otherwise we wouldn't be here right now. :)

Do you have any suggestions as to how I could make it better?

Upvotes: 2

Related Questions