@0xtld/tair-node
Version:
A Node.js package for Tair functionality with configuration, core, and helper modules.
58 lines (57 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const express_1 = tslib_1.__importDefault(require("express"));
const core_1 = require("./core");
const helpers_1 = require("./helpers");
const app = (0, express_1.default)();
const port = 3000;
const mailRest = new core_1.MailRest({
account: {
address: '',
password: ''
},
gateway: core_1.EMailRestGateway.MAIL_GW,
maximumRetries: 20,
});
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.post('/login', async (req, res) => {
const { email, password } = req.body;
try {
mailRest.setAccount({
address: email,
password: password
});
await mailRest.login();
res.json({
token: mailRest.token,
});
}
catch (error) {
res.status(500).json({
error: 'Something went wrong',
});
}
});
app.post('/getMessageOtp', async (req, res) => {
const { emailReceipt } = req.body;
try {
const message = await helpers_1.AsyncHelper.retryOperation(() => mailRest.getMessageByAddress(emailReceipt), {
maxAttempts: 20,
delay: 1000,
});
res.json({
data: message,
});
}
catch (error) {
res.status(500).json({
error: 'Something went wrong',
});
}
});