Spaces:
Sleeping
Sleeping
| 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}`); | |
| }); |