var express = require('express'); var avatar = require('ssb-avatar'); var client = require('ssb-client'); var pull = require('pull-stream'); var moment = require('moment'); var markdown = require('marked'); var nm = require('nodemailer'); var bodyParser = require('body-parser'); var app = express(); app.set('view engine', 'jade'); app.set('views', './layouts'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); const me = '@ya/sq19NPxRza5xtoqi9BilwLZ7HgQjG3QpcTRnGgWs=.ed25519' const site = 'Gwen Bell'; app.get('/', function (req, res) { client(function (err, sbot) { if (err) { throw err; } avatar(sbot, me, me, function (err, avatar){ if (err) { throw err; } name = avatar.name; image = avatar.image; }) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { getpin = data; pull( sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}), pull.drain(function (data){ pinned = data; }) ) }) ) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { post = data; }) ) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { vote = data; pull( sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}), pull.drain(function (reblog) { avatar(sbot, me, reblog.value.author, function (err, avatar){ if (err) { throw err; } reauthor = avatar; gotPost(); }) redo = reblog; }) ) }) ) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { gits = data; }) ) }); function gotPost() { res.render('index', { title: site, markdown, moment}); } }); app.post('/send', function (req, res) { var name = req.body.nombre; var email = req.body.elmail; var website = req.body.siteurl; var date = moment().format('MMMM D, YYYY'); var str = name + " <" + email + "> " + website + " - " + date; var transporter = nm.createTransport(); transporter.sendMail({ from: email, to: 'gwen@gwenbell.com', subject: 'New signup!', text: str }); res.redirect('http://gwenbell.com/'); }); app.use(express.static('./../books/build')) app.use(express.static('/static/reserva')) app.use(express.static('build')) app.listen(2525); console.log('Listening at http://localhost:2525/');