Skip to content

Instantly share code, notes, and snippets.

@bergos
Last active November 1, 2015 20:17
Show Gist options
  • Select an option

  • Save bergos/b8a053699feeb7ff6d84 to your computer and use it in GitHub Desktop.

Select an option

Save bergos/b8a053699feeb7ff6d84 to your computer and use it in GitHub Desktop.
'use strict';
var
fs = require('fs'),
path = require('path');
var buildQuery = function (iri) {
return 'DESCRIBE <' + iri + '>';
};
var buildExistsQuery = function (iri) {
return 'ASK { GRAPH <http://dbpedia.org> { <' + iri + '> ?p ?o }}';
};
var patchResponseHeaders = function (res, headers) {
if (res.statusCode === 200) {
// clean existings values
var fieldList = [
'Access-Control-Allow-Origin',
'Cache-Control',
'Fuseki-Request-ID',
'Server',
'Vary'];
if (res._headers) {
fieldList.forEach(function (field) {
if (field in res._headers) {
delete res._headers[field];
}
if (field.toLowerCase() in res._headers) {
delete res._headers[field.toLowerCase()];
}
});
}
// cors header
headers['Access-Control-Allow-Origin'] = '*';
// cache header
headers['Cache-Control'] = 'public, max-age=120';
// vary header
headers['Vary'] = 'Accept';
}
return headers;
};
module.exports = {
app: 'trifid-ld',
hostname: 'dbpedia.org',
port: '',
logger: {
level: 'debug'
},
listener: {
port: 80
},
expressSettings: {
'trust proxy': 'loopback',
'x-powered-by': null
},
patchHeaders: {
patchResponse: patchResponseHeaders
},
sparqlProxy: {
path: '/raw/sparql',
options: {
endpointUrl:'http://dbpedia.org/sparql',
queryOperation: 'urlencoded'
}
},
sparqlSearch: {
path: '/query',
options: {
endpointUrl:'http://dbpedia.org/sparql',
resultsPerPage: 5,
queryTemplate: fs.readFileSync(path.join(__dirname, 'data/sparql/search.sparql')).toString(),
variables: {
'q': {
variable: '%searchstring%',
required: true
}
}
}
},
HandlerClass: require('./lib/sparql-handler'),
handlerOptions: {
endpointUrl: 'http://dbpedia.org/sparql',
buildQuery: buildQuery,
buildExistsQuery: buildExistsQuery,
hostname: 'dbpedia.org',
port: ''
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment