ruby - How to render the javascript frontend application, in rails json API architecture? -
i working on rails app, front end on martyjs/reactjs. i've set route matches every pattern, user can follow link deep in reactjs app. implementing login/logout , i've came problem. in application_controller.rb
i've set filter:
before_action :authenticated_account? def authenticated_account? customer = user::customer.find_by_session_token cookies.signed[:session_token] if customer.verify_session!(cookies.signed[:session_token],request.remote_ip ) else resp = response.new("not authorized", nil, 401) end return respond resp if resp end
but rightly, deny interface render, since server receive json message. response when app loaded, because app intercept gracefully 401 code.
but not find out soluton rendering js app , respond code if user open window , go link directly deep in reactjs app.
like i've said, knew missing something. i've dedicated controller action render of html page onepageapplication, , skipped authentication check on that.
so, recap:
to serve onepageapp rails.
set route api calls:
namespace :api ... end
and route serving ui:
scope "/", :format => false "/" => "application#uiserve" "/*path" => "application#uiserve" root :to => "application#index" end
in way, when user digit deep link in app, matched, , served html page js code.
the requests app make, under namespace :api
routed correctly
Comments
Post a Comment