Cross-Origin Resource Sharing (CORS)

Cross-Origin Resource Sharing (CORS) enables Javascript access across domain boundaries.

Ontologies should to be CORS Enabled to enable javascript clients to reason over them.

The CORS Enabled wiki page details how to get CORS enabled. It also lists existing services, sparql endpoints, datasets and ontologies that are javascript accessible.

CORS on Apache

To enable CORS on Apache add the following to the .htaccess file.

Header set Access-Control-Allow-Origin "*"

CORS on PHP

To enable CORS with PHP add the following to the PHP scripts.

<?php
header("Access-Control-Allow-Origin: *");

CORS on ExpressJS

To enable CORS with ExpressJS add the following to the routes.

app.all('*', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  next();
});

app.get('/', function(req, res, next) {
  // Handle the get for this route
});

app.post('/', function(req, res, next) {
// Handle the post for this route
});

CORS in AngularJS

To enable CORS in AngularJS add the following to the app.

var myApp = angular.module('myApp', [   
        'myAppApiService']);

myApp.config(['$httpProvider', function($httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];
    }
]);

References