-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathtwitter.js
29 lines (29 loc) · 1.18 KB
/
twitter.js
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
// 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");