-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathog.js
46 lines (33 loc) · 1.02 KB
/
og.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
36
37
38
39
40
41
42
43
44
45
46
var express = require('express');
var og = require('open-graph');
var apicache = require('apicache').options({ debug: true }).middleware;
var allowCrossDomain = function(req, res, next) {
//res.header('Access-Control-Allow-Origin', 'buddycloud.org');
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
var app = express();
app.use(allowCrossDomain);
//var url = "http://github.com/samholmes/node-open-graph/raw/master/test.html";
app.get('/',apicache('10 days'), function (req, res) {
og(req.query.url, function(err, meta){
if(err){
res.send(err);
}else{
res.json(meta);
res.end();
}
})
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
/*
og(url, function(err, meta){
console.log(meta);
})
*/