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

Open
by Ghost opened 2 years ago · 0 comments
Ghost commented 2 years ago

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

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.