close

  
<p> function redirect(endpoint) { 
  var url = acre.form.build_url(acre.request.base_url + endpoint, acre.request.params);
  acre.response.status = "301";
  acre.response.set_header('Location', url);
}

var endpoints = { '/type/user' : 'user', 
                  '/type/domain' : 'domain', 
                  '/type/type' : 'type', 
                  '/type/property' : 'property', 
                  '/type/namespace' : 'namespace'};

var id = acre.request.params['id'] ? acre.request.params['id'] : '/user/jon';

if (id.indexOf('_') == 0) { 
  redirect('property');
  acre.exit();
}

var object_info = acre.require('object_info').query;
acre.freebase.extend_query(object_info, { 'id' : id });

var result = acre.freebase.mqlread(object_info).result;

for (i in result['type']) { 
  if (endpoints[result['type'][i]]) { 
    redirect(endpoints[result['type'][i]]);
    break;
  }
  
}
 </p>

Comments

Hide