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;
```
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
app.ts