b1f69e16f6
Also a new "Wheee!" page when the email-sending is done 😉
65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
const express = require('express')
|
|
|
|
require('dotenv').config()
|
|
|
|
const app = express()
|
|
var expressWs = require('express-ws')(app)
|
|
|
|
const port = process.env.port || 5000
|
|
|
|
const cors = require('cors')
|
|
const path = require('path')
|
|
|
|
app.use(cors())
|
|
|
|
app.get('/air', (req, res) => {
|
|
console.log(`Searching for contacts with the term: ${req.query.name}`)
|
|
res.send({
|
|
success: true,
|
|
data: [],
|
|
})
|
|
})
|
|
|
|
app.ws('/hit-send', (ws, request) => {
|
|
console.log('Hitting send on some emails!')
|
|
|
|
ws.on('message', (message) => {
|
|
try {
|
|
message = JSON.parse(message)
|
|
} catch(err) {
|
|
ws.send(JSON.stringify({
|
|
success: false,
|
|
error: "We can't understand what you're saying! Me speak JSON only.",
|
|
}))
|
|
return
|
|
}
|
|
|
|
console.log(`\n\n-------------------------- BEGIN EMAIL --------------------------\n`)
|
|
console.log(`From: ${message.from}\nTo:${message.to}\n\n${message.text}`)
|
|
console.log(`\n--------------------------- END EMAIL ---------------------------`)
|
|
|
|
// TODO: actually send the email
|
|
|
|
setTimeout(() => {
|
|
ws.send(JSON.stringify({
|
|
success: true,
|
|
from: message.from,
|
|
to: message.to,
|
|
}))
|
|
}, 2000)
|
|
})
|
|
|
|
ws.on('close', () => {
|
|
console.log('socket closed')
|
|
})
|
|
})
|
|
|
|
app.use(express.static('public'))
|
|
app.get('/', (req, res) => {
|
|
res.sendFile(path.resolve(__dirname, 'public', 'index.html'))
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Server is up at port ${port}`)
|
|
})
|