mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 11:20:57 -06:00
22789e0201
Discourse needs a bunch of data preloaded before it can start up. Normally we throw blobs of this into the HTML document that is requested but in some cases that's awkward to retrieve. For example with Ember CLI you have a separate javascript application that needs to make its own HTML. This API endpoint returns a JSON object with all the data Discourse needs to bootstrap and start up.
30 lines
834 B
Ruby
30 lines
834 B
Ruby
# frozen_string_literal: true
|
|
|
|
class BootstrapController < ApplicationController
|
|
include ApplicationHelper
|
|
include ActionView::Helpers::AssetUrlHelper
|
|
|
|
# This endpoint allows us to produce the data required to start up Discourse via JSON API,
|
|
# so that you don't have to scrape the HTML for `data-*` payloads
|
|
def index
|
|
locale = script_asset_path("locales/#{I18n.locale}")
|
|
|
|
preload_anonymous_data
|
|
if current_user
|
|
current_user.sync_notification_channel_position
|
|
preload_current_user_data
|
|
end
|
|
|
|
bootstrap = {
|
|
theme_ids: theme_ids,
|
|
title: SiteSetting.title,
|
|
current_homepage: current_homepage,
|
|
locale_script: "#{Discourse.base_url}#{locale}",
|
|
setup_data: client_side_setup_data,
|
|
preloaded: @preloaded
|
|
}
|
|
|
|
render_json_dump(bootstrap: bootstrap)
|
|
end
|
|
end
|