mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
Publish DFC endpoints as JSON
This commit is contained in:
13
app/controllers/well_known_controller.rb
Normal file
13
app/controllers/well_known_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WellKnownController < ApplicationController
|
||||
layout nil
|
||||
|
||||
def dfc
|
||||
base = "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/scopes.rdf#"
|
||||
render json: {
|
||||
"#{base}ReadEnterprise" => "/api/dfc/enterprises/",
|
||||
"#{base}ReadProducts" => "/api/dfc/supplied_products/",
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -29,6 +29,9 @@ Openfoodnetwork::Application.routes.draw do
|
||||
get '/orders/:id/token/:token' => 'spree/orders#show', :as => :token_order
|
||||
get '/payments/:id/authorize' => 'payments#redirect_to_authorize', as: "authorize_payment"
|
||||
|
||||
# Well known paths
|
||||
get "/.well-known/dfc/", to: "well_known#dfc"
|
||||
|
||||
resource :cart, controller: "cart" do
|
||||
post :populate
|
||||
end
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/scopes.rdf#ReadEnterprise": "/api/dfc/enterprises/",
|
||||
"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/scopes.rdf#ReadProducts": "/api/dfc/supplied_products/",
|
||||
}
|
||||
@@ -8,8 +8,9 @@ RSpec.describe "/.well-known/" do
|
||||
get "/.well-known/dfc/"
|
||||
|
||||
expect(response).to have_http_status :ok
|
||||
expect(response.content_type).to eq "text/plain" # Should be JSON!
|
||||
expect(response.body).to include "ReadEnterprise"
|
||||
expect(response.content_type).to eq "application/json; charset=utf-8"
|
||||
expect(response.parsed_body.count).to eq 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user