Stub out a /demo endpoint
parent
ee86966eba
commit
42d4fcba16
|
@ -3,43 +3,45 @@ class DashboardController < ApplicationController
|
|||
layout "dashboard"
|
||||
|
||||
# === THESE CONSTANTS ARE CONFIGURABLE: ===
|
||||
EVERY_STATIC_PAGE = [ :front_page,
|
||||
:main_app,
|
||||
:password_reset,
|
||||
:tos_update, ]
|
||||
EVERY_STATIC_PAGE = [:front_page,
|
||||
:main_app,
|
||||
:password_reset,
|
||||
:tos_update,
|
||||
:demo]
|
||||
|
||||
OUTPUT_URL = "/" + File.join("assets", "parcel") # <= served from public/ dir
|
||||
# <= See PUBLIC_OUTPUT_DIR
|
||||
CACHE_DIR = File.join(".cache")
|
||||
CACHE_DIR = File.join(".cache")
|
||||
|
||||
CSS_INPUTS = {
|
||||
CSS_INPUTS = {
|
||||
front_page: "/css/laptop_splash.scss",
|
||||
default: "/css/_index.scss",
|
||||
default: "/css/_index.scss",
|
||||
}.with_indifferent_access
|
||||
|
||||
JS_INPUTS = {
|
||||
main_app: "/entry.tsx",
|
||||
front_page: "/front_page/index.tsx",
|
||||
JS_INPUTS = {
|
||||
main_app: "/entry.tsx",
|
||||
front_page: "/front_page/index.tsx",
|
||||
password_reset: "/password_reset/index.tsx",
|
||||
tos_update: "/tos_update/index.tsx",
|
||||
tos_update: "/tos_update/index.tsx",
|
||||
demo: "/demo/index.tsx",
|
||||
}.with_indifferent_access
|
||||
|
||||
# === THESE CONSTANTS ARE NON-CONFIGURABLE. ===
|
||||
# They are calculated based on config above.
|
||||
|
||||
RELEASE_CHUNK = GlobalConfig::LONG_REVISION == "NONE" ?
|
||||
RELEASE_CHUNK = GlobalConfig::LONG_REVISION == "NONE" ?
|
||||
SecureRandom.hex.first(5) : GlobalConfig::LONG_REVISION
|
||||
CACHE_BUST_STRING = "?version=#{RELEASE_CHUNK}"
|
||||
PUBLIC_OUTPUT_DIR = File.join("public", OUTPUT_URL)
|
||||
|
||||
CSS_OUTPUTS = CSS_INPUTS.reduce({}) do |acc, (k, v)|
|
||||
file = v.gsub(/\.scss$/, ".css")
|
||||
file = v.gsub(/\.scss$/, ".css")
|
||||
acc[k] = File.join(OUTPUT_URL, file)
|
||||
acc
|
||||
end.with_indifferent_access
|
||||
|
||||
JS_OUTPUTS = JS_INPUTS.reduce({}) do |acc, (k, v)|
|
||||
file = v.gsub(/\.tsx?$/, ".js")
|
||||
file = v.gsub(/\.tsx?$/, ".js")
|
||||
acc[k] = File.join(OUTPUT_URL, file)
|
||||
acc
|
||||
end.with_indifferent_access
|
||||
|
@ -50,9 +52,9 @@ class DashboardController < ApplicationController
|
|||
.map { |x| File.join("frontend", x) }
|
||||
.join(" ")
|
||||
|
||||
PARCEL_HMR_OPTS = [
|
||||
PARCEL_HMR_OPTS = [
|
||||
"--no-hmr",
|
||||
"--no-cache"
|
||||
"--no-cache",
|
||||
].join(" ")
|
||||
|
||||
EVERY_STATIC_PAGE.map do |actn|
|
||||
|
@ -61,22 +63,22 @@ class DashboardController < ApplicationController
|
|||
# If you don't do this, you will hit hard to debug
|
||||
# CSP errors on local when changing API_HOST.
|
||||
response.headers["Cache-Control"] = "no-cache, no-store"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
response.headers["Expires"] = "0"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
response.headers["Expires"] = "0"
|
||||
load_css_assets
|
||||
load_js_assets
|
||||
render actn
|
||||
rescue ActionView::MissingTemplate => q
|
||||
raise ActionController::RoutingError, "Bad URL in dashboard"
|
||||
raise ActionController::RoutingError, "Bad URL in dashboard. -Rick"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def confirmation_page
|
||||
load_css_assets
|
||||
user = User.find_by!(confirmation_token: params.fetch(:token))
|
||||
user = User.find_by!(confirmation_token: params.fetch(:token))
|
||||
# Two use cases: re-confirmation Email change
|
||||
klass = user.unconfirmed_email? ? Users::Reverify : Users::Verify
|
||||
klass = user.unconfirmed_email? ? Users::Reverify : Users::Verify
|
||||
@token = klass.run!(user: user).to_json
|
||||
render :confirmation_page
|
||||
rescue User::AlreadyVerified
|
||||
|
@ -90,7 +92,7 @@ class DashboardController < ApplicationController
|
|||
begin
|
||||
report = JSON.parse(payload)
|
||||
rescue
|
||||
report = {problem: "Crashed while parsing report"}
|
||||
report = { problem: "Crashed while parsing report" }
|
||||
end
|
||||
Rollbar.info("CSP Violation", report)
|
||||
|
||||
|
@ -101,13 +103,14 @@ class DashboardController < ApplicationController
|
|||
# Do not use this if you use GCS- it will slow your app down.
|
||||
def direct_upload
|
||||
raise "No." unless Api::ImagesController.store_locally
|
||||
name = params.fetch(:key).split("/").last
|
||||
path = File.join("public", "direct_upload", "temp", name)
|
||||
name = params.fetch(:key).split("/").last
|
||||
path = File.join("public", "direct_upload", "temp", name)
|
||||
File.open(path, "wb") { |f| f.write(params[:file]) }
|
||||
render json: ""
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def load_css_assets
|
||||
@css_assets ||= [action_name, :default].reduce([]) do |list, action|
|
||||
asset = CSS_OUTPUTS[action] # Not every endpoint has custom CSS.
|
||||
|
@ -118,8 +121,8 @@ private
|
|||
|
||||
def load_js_assets
|
||||
# Every DashboardController has a JS SBundle.
|
||||
@js_assets ||= \
|
||||
[ JS_OUTPUTS.fetch(action_name) ].map { |x| x + CACHE_BUST_STRING }
|
||||
@js_assets ||=
|
||||
[JS_OUTPUTS.fetch(action_name)].map { |x| x + CACHE_BUST_STRING }
|
||||
end
|
||||
|
||||
def set_global_config
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<%# Intentionally blank template required by router for content generated by frontend. %>
|
|
@ -108,8 +108,9 @@ FarmBot::Application.routes.draw do
|
|||
get "/app/controls" => "dashboard#main_app", as: :app_landing_page
|
||||
match "/app/*path", to: "dashboard#main_app", via: :all, constraints: { format: "html" }
|
||||
|
||||
get "/tos_update" => "dashboard#tos_update", as: :tos_update
|
||||
get "/demo" => "dashboard#demo", as: :demo_main
|
||||
get "/password_reset/*token" => "dashboard#password_reset", as: :password_reset
|
||||
get "/tos_update" => "dashboard#tos_update", as: :tos_update
|
||||
get "/verify/:token" => "dashboard#confirmation_page", as: :confirmation_page
|
||||
post "/csp_reports" => "dashboard#csp_reports", as: :csp_report
|
||||
post "/direct_upload" => "dashboard#direct_upload", as: :direct_upload
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
document.write("It works!");
|
Loading…
Reference in New Issue