Spaces:
Runtime error
Runtime error
File size: 1,026 Bytes
3c0a3bf 7162102 3c0a3bf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | const express = require('express');
const path = require('path');
const TempMailCore = require('./tempmail');
const app = express();
const tm = new TempMailCore();
app.use(express.json());
// serve web
app.get('/', (_, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
/*
CLONE API STYLE
contoh:
/api/email/new -> temp-mail /email/new
*/
// list domain
app.get('/api/domains', async (_, res) => {
res.json(await tm.listDomains());
});
// create email
app.post('/api/email/new', async (req, res) => {
const { name, domain } = req.body;
if (!name || !domain)
return res.json({ success:false, error:'name & domain required' });
res.json(await tm.generateEmail(name, domain));
});
// inbox
app.get('/api/email/:email/messages', async (req, res) => {
res.json(await tm.checkEmail(req.params.email));
});
const PORT = process.env.PORT || 7860;
app.listen(PORT, () => {
console.log(`๐ Temp Email Farel running`);
console.log(`๐ http://localhost:${PORT}`);
}); |