Problems upgrading a simple setup from v2 to v4. #40

Closed
opened 2020-04-17 19:59:21 +00:00 by Ghost · 2 comments

Hey @solderjs,

it is really awesome that you wrote the new version, and I would love to update. I tried to a twice already, but it is very confusing for me what I need to change.

My current v2 setup is the following:

server.js

const Greenlock = require('greenlock-express')

const contentful = require('./services/contentful')
const letsencryptConfig = require('./config/letsencrypt')
const startServer = async () => {
  const app = await require('./app.js')()
  const greenlock = Greenlock.create(Object.assign(letsencryptConfig, { app: app }))
  // development server
  if (process.env.NODE_ENV === 'development') {
    console.log('Environment: ' + process.env.NODE_ENV)
    console.log('✅ Listening on http://localhost:8080')
    app.listen('8080')
  } else if (process.env.NODE_ENV === 'test') {
    app.listen(process.env.NODE_PORT || '3300')
  } else {
    // live server server
    greenlock.listen(80, 443)
  }
}

// contentful has loaded
contentful(startServer, (error) => {
  console.log(`🚨 \x1b[31mError: ${error.code} when trying to connect to ${error.hostname}\x1b[0m`)
  // run routes even when contentful connection fails
  startServer()
})

./config/letsencrypt

module.exports = {
  // Let's Encrypt v2 is ACME draft 11
  version: 'draft-11',
  // staging server
  // server: 'https://acme-staging-v02.api.letsencrypt.org/directory',
  // production server
  server: 'https://acme-v02.api.letsencrypt.org/directory',
  maintainerEmail: 'oppermann.lukas@gmail.com',
  agreeTos: true,
  approvedDomains: [
    'lukas-oppermann.de', 'www.lukas-oppermann.de',
    'lukasoppermann.de', 'www.lukasoppermann.de',
    'lukasoppermann.com', 'www.lukasoppermann.com',
    'vea.re', 'www.vea.re',
    'veare.de', 'www.veare.de'
  ],
  store: require('greenlock-store-fs'),
  // You MUST have access to write to directory where certs are saved
  // ex: /home/foouser/acme/etc
  configDir: '/home/shared/acme/etc', // MUST have write access,
  communityMember: true
}

This is very simple. I don't need any more flexibility as I have a simple website.
I would like to avoid a ./greenlock.d file and if possible keep this to just an additional config file.

Can you please let me know how I can replicate this setup with v4?
Thank you very much.

Hey @solderjs, it is really awesome that you wrote the new version, and I would love to update. I tried to a twice already, but it is very confusing for me what I need to change. My current v2 setup is the following: **server.js** ```js const Greenlock = require('greenlock-express') const contentful = require('./services/contentful') const letsencryptConfig = require('./config/letsencrypt') const startServer = async () => { const app = await require('./app.js')() const greenlock = Greenlock.create(Object.assign(letsencryptConfig, { app: app })) // development server if (process.env.NODE_ENV === 'development') { console.log('Environment: ' + process.env.NODE_ENV) console.log('✅ Listening on http://localhost:8080') app.listen('8080') } else if (process.env.NODE_ENV === 'test') { app.listen(process.env.NODE_PORT || '3300') } else { // live server server greenlock.listen(80, 443) } } // contentful has loaded contentful(startServer, (error) => { console.log(`🚨 \x1b[31mError: ${error.code} when trying to connect to ${error.hostname}\x1b[0m`) // run routes even when contentful connection fails startServer() }) ``` **./config/letsencrypt** ```js module.exports = { // Let's Encrypt v2 is ACME draft 11 version: 'draft-11', // staging server // server: 'https://acme-staging-v02.api.letsencrypt.org/directory', // production server server: 'https://acme-v02.api.letsencrypt.org/directory', maintainerEmail: 'oppermann.lukas@gmail.com', agreeTos: true, approvedDomains: [ 'lukas-oppermann.de', 'www.lukas-oppermann.de', 'lukasoppermann.de', 'www.lukasoppermann.de', 'lukasoppermann.com', 'www.lukasoppermann.com', 'vea.re', 'www.vea.re', 'veare.de', 'www.veare.de' ], store: require('greenlock-store-fs'), // You MUST have access to write to directory where certs are saved // ex: /home/foouser/acme/etc configDir: '/home/shared/acme/etc', // MUST have write access, communityMember: true } ``` This is very simple. I don't need any more flexibility as I have a simple website. I would like to avoid a `./greenlock.d` file and if possible keep this to just an additional config file. Can you please let me know how I can replicate this setup with v4? Thank you very much.
Owner

Rather than trying to "migrate", just follow the quickstart from scratch:

https://git.coolaj86.com/coolaj86/greenlock-express.js#user-content-v4-quickstart

A couple of notes:

  • configDir is greenlock.d and that is where domains are stored, which in the simplest case should be the same as where the certificates are stored.
  • For simple sites, the npx commands shown in the QuickStart are the best way to go. I streamlined away the option for using a static array because it was syntax sugar that cost more than it delivered.

I'd also suggest flattening your dev / prod check to something like this:

  if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
    // or just leave the two or three lines as-is
    require('./server-dev.js').serve(whatever);
  } else {
    // move greenlock-related stuff away into its own thing
    require('./server-https.js').serve(whatever);
  }

And then I think you'll be able to use the serve(app) as shown in the quickstart.

Rather than trying to "migrate", just follow the quickstart from scratch: https://git.coolaj86.com/coolaj86/greenlock-express.js#user-content-v4-quickstart A couple of notes: - `configDir` is `greenlock.d` and that is where domains are stored, which in the simplest case should be the same as where the certificates are stored. - For simple sites, the `npx` commands shown in the QuickStart are the best way to go. I streamlined away the option for using a static array because it was syntax sugar that cost more than it delivered. I'd also suggest flattening your dev / prod check to something like this: ```js if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') { // or just leave the two or three lines as-is require('./server-dev.js').serve(whatever); } else { // move greenlock-related stuff away into its own thing require('./server-https.js').serve(whatever); } ``` And then I think you'll be able to use the `serve(app)` as shown in the quickstart.
Owner

It's definitely inverted from the previous version, which has been an issue for long-time users.

However, the changes make for less configuration overall and streamlined "one right way" to do things - which means that it works the same for 1 domain deployments as for 10,000 domain deployments, without having to have separate documentation.

It's definitely inverted from the previous version, which has been an issue for long-time users. However, the changes make for less configuration overall and streamlined "one right way" to do things - which means that it works the same for 1 domain deployments as for 10,000 domain deployments, without having to have separate documentation.
Ghost closed this issue 2020-08-05 15:27:27 +00:00
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: root/greenlock-express.js#40
No description provided.