-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (29 loc) · 961 Bytes
/
index.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
30
31
32
33
34
35
var express = require('express');
var compress = require('compression');
var createTweets = require('./tweets');
var fs = require('fs');
var ONE_DAY = 86400000;
var config = require('../config.json');
config.application_only = true;
config.cacheDir = __dirname + '/../cache';
var tweets = createTweets(config);
var app = express();
app.use(compress());
app.use(express.static(__dirname + '/../client', { maxAge: ONE_DAY }));
app.get('/', (function() {
return function(req, res) {
var content = fs.readFileSync(__dirname + '/../client/index.html');
res.end(content);
};
}()));
app.get('/tweet/:id', function(req, res) {
res.type('text/plain');
res.header('Cache-Control', 'public, max-age=' + (ONE_DAY / 1000));
tweets.embedCode(req.params.id).then(function(html) {
res.end(html);
}, function() {
res.end('error');
});
});
app.listen(process.env.PORT || 3000);
console.log('\n Server listening at http://localhost:3000/\n');