class Forest::ChartsController < ForestLiana::ApplicationController
require 'google/apis/webmasters_v3'
require 'googleauth'
require 'net/http'
require 'uri'
require 'json'
def non_optimized_articles
# logic to get data
stat = ForestLiana::Model::Stat.new({ value: data })
render json: serialize_model(stat)
end
end
config/application.rb:
module Lalanguefrancaisev3
class Application < Rails::Application
null_regex = Regexp.new(/\Anull\z/)
config.middleware.insert_before 0, Rack::Cors do
allow do
hostnames = [null_regex, 'localhost:4200', 'app.forestadmin.com', 'localhost:3001']
hostnames += ENV['CORS_ORIGINS'].split(',') if ENV['CORS_ORIGINS']
origins hostnames
resource '*',
headers: :any,
methods: :any,
expose: ['Content-Disposition'],
credentials: true
end
end
end
end
The weird thing is WpPostsController#create is called, I don’t know why…
Expected behavior
The chart should display the data properly.
Failure Logs
Started POST “/stats/non-optimized-articles?timezone=Europe%2FIstanbul” for ::1 at 2022-09-17 09:47:18 +0300
Processing by WpPostsController#create as JSON
Parameters: {“type”=>“Leaderboard”, “limit”=>nil, “timezone”=>“Europe/Istanbul”, “category”=>“stats”, “subcategory”=>“non-optimized-articles”, “wp_post”=>{}}
HTTP Origin header (https://app.forestadmin.com) didn’t match request.base_url (http://localhost:3000)
Completed 422 Unprocessable Entity in 2ms (Allocations: 761)
Started POST “/stats/non-optimized-articles?timezone=Europe%2FIstanbul” for ::1 at 2022-09-17 09:47:18 +0300
Hello @matthv,
Thanks for your reply. Here are my Forest routes:
namespace :forest do
post '/actions/generate-newsletter-campaign' => 'newsletters#generate_newsletter_campaign'
post '/actions/create-new-word' => 'words#create_new_word'
post '/actions/search-variant' => 'words#search_variant'
post '/actions/generate-audio-url' => 'quiz_questions#generate_audio_url'
post '/actions/generate-audio-url' => 'quiz_questions#generate_audio_url'
post '/stats/non-optimized-articles' => 'charts#non_optimized_articles'
end
mount ForestLiana::Engine => '/forest'
If I change “charts#non_optimized” to “ChartsController#non_optimized” I get the following error:
‘forest/ChartsController’ is not a supported controller name.
Note that “charts_controller.rb” is located in app/controllers/forest/charts_controller.rb
Here are the network logs in development environment. Please let me know if you need some details: