server.js
1.21 KB
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
var path = require('path'),
express = require('express'),
exphbs = require('express-handlebars'),
iframeReplacement = require('../index.js');
function Server() {
// create an instance of express
var app = express();
// add iframe replacement to express as middleware (adds res.merge method)
app.use(iframeReplacement);
// add handlebars view engine (you can use any)
app.engine('hbs', exphbs());
// let express know how to locate the views/templates
app.set('views', path.resolve(__dirname, 'views'));
app.set('view engine', 'hbs');
// create simple route to test our fake news
app.get('/', function(req, res) {
// respond to this request with our fake-new content embedded within the BBC News home page
res.merge('fake-news', {
sourceUrl: 'http://www.bbc.co.uk/news', // external url to fetch
sourcePlaceholder: 'div[data-entityid="container-top-stories#1"]' // css selector to inject our content into
});
});
// start the server
app.listen(8080, function() {
console.log('Server running... Visit http://localhost:8080 in your browser');
});
}
module.exports = new Server();