UNPKG

lispyscript

Version:

A JavaScript with Lispy Syntax and Macros

30 lines (29 loc) 1.21 kB
// Generated by LispyScript v1.0.0 var express = require("express"); var bodyParser = require("body-parser"); var app = express(); app.listen(3000); var base = function(title,header,body) { return ["<!DOCTYPE html>\n<html>\n<head>\n <title>",title,"</title>\n</head>\n<body>\n <h1>",header,"</h1>",body,"</body>\n</html>"].join(''); }; var index = function() { return ["<h2>Enter Tweet</h2>\n<form action='/send' method='POST'>\n <input type='text' length='140' name='tweet'/>\n <input type='submit' value='Tweet'/>\n</form>\n<h2>All Tweets</h2>",(tweets).reduce(function(___memo,elem,index) { return (___memo + ["<div>",elem,"</div>"].join('')); },"")].join(''); }; var tweets = []; app.get("/",function(req,res) { return res.send(base("Our Own Twitter","Our Own Twitter",index())); }); app.post("/send",bodyParser(),function(req,res) { return ((req.body && req.body.tweet) ? (function() { tweets.push(req.body.tweet); return res.redirect("/"); })() : res.send({status: "nok", message: "No tweet Received"})); }); app.get("/tweets",function(req,res) { return res.send(tweets); }); console.log("Listening on port 3000");