Dry challenge failed while using greenlock.js without using express module #44

Open
opened 2022-04-25 07:31:19 +00:00 by Ghost · 0 comments

I am trying to use only the greenlock package in my project and i want to add domain programmatically.The code is given below

index.ts

const app = require('./app.ts');
const path = require('path');
const pkg = require('../package.json');
const rootdir = path.join(__dirname, '../');
console.log(rootdir);
const Greenlock = require('greenlock');
const greenlock = Greenlock.create({
    packageRoot: rootdir,
    configDir: './greenlock.d/',
    packageAgent: pkg.name + '/' + pkg.version,
    maintainerEmail: 'mir@bonton.app',
    staging: false,
    notify: function (event: any, details: any) {
        if ('error' === event) {
            // `details` is an error object in this case
            console.error('details', details);
        }
    },
});


greenlock.manager.defaults(
    {
        agreeToTerms: true,
        subscriberEmail: 'example@mail.com',
    },
    (fullConfig: any) => {
        console.log('fullconfig: ', fullConfig);
    },
);

const altnames = ['example.com'];

greenlock
    .add({
        subject: altnames[0],
        altnames: altnames,
    })
    .then(function (data: any) {
        // saved config to db (or file system)
        console.log('config', data);
    });

app.listen(80);
app.listen(443);

app.ts

import express, {Request, Response} from 'express';

const app = express();

app.use('/', function (req: Request, res: Response) {
    const host = req.get('host');
    res.send(`Hello World From ${host}`);
});

// DO NOT DO app.listen() unless we're testing this directly
if (require.main === module) {
    app.listen(3000);
}

// Instead do export the app:
module.exports = app;
I am trying to use only the greenlock package in my project and i want to add domain programmatically.The code is given below index.ts ``` const app = require('./app.ts'); const path = require('path'); const pkg = require('../package.json'); const rootdir = path.join(__dirname, '../'); console.log(rootdir); const Greenlock = require('greenlock'); const greenlock = Greenlock.create({ packageRoot: rootdir, configDir: './greenlock.d/', packageAgent: pkg.name + '/' + pkg.version, maintainerEmail: 'mir@bonton.app', staging: false, notify: function (event: any, details: any) { if ('error' === event) { // `details` is an error object in this case console.error('details', details); } }, }); greenlock.manager.defaults( { agreeToTerms: true, subscriberEmail: 'example@mail.com', }, (fullConfig: any) => { console.log('fullconfig: ', fullConfig); }, ); const altnames = ['example.com']; greenlock .add({ subject: altnames[0], altnames: altnames, }) .then(function (data: any) { // saved config to db (or file system) console.log('config', data); }); app.listen(80); app.listen(443); ``` app.ts ``` import express, {Request, Response} from 'express'; const app = express(); app.use('/', function (req: Request, res: Response) { const host = req.get('host'); res.send(`Hello World From ${host}`); }); // DO NOT DO app.listen() unless we're testing this directly if (require.main === module) { app.listen(3000); } // Instead do export the app: module.exports = app; ```
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 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.js#44
No description provided.