From e311b9314d62e4670caac7bb31476392bb7b0417 Mon Sep 17 00:00:00 2001 From: "T. Brandon Ashley" Date: Sat, 2 Feb 2019 00:33:48 -0500 Subject: [PATCH] fix(*): set public path dynamically to fetch from cdn (#80) --- assets/src/Ellie/Constants.js | 5 +++++ assets/src/Pages/Editor/index.js | 3 +++ assets/src/Pages/Embed/index.js | 3 +++ assets/webpack.dev.config.js | 6 +++--- lib/ellie_web/endpoint.ex | 14 ++++++-------- lib/ellie_web/templates/page/editor.html.eex | 1 + lib/ellie_web/templates/page/embed.html.eex | 1 + 7 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 assets/src/Ellie/Constants.js diff --git a/assets/src/Ellie/Constants.js b/assets/src/Ellie/Constants.js new file mode 100644 index 00000000..b82f711a --- /dev/null +++ b/assets/src/Ellie/Constants.js @@ -0,0 +1,5 @@ +export default { + publicPath: () => { + return document.head.querySelector("meta[name='public_path']").content; + } +}; diff --git a/assets/src/Pages/Editor/index.js b/assets/src/Pages/Editor/index.js index 08ee421e..7867f961 100644 --- a/assets/src/Pages/Editor/index.js +++ b/assets/src/Pages/Editor/index.js @@ -23,12 +23,15 @@ import EllieUiCopyText from "../../Ellie/Ui/CopyText"; import EllieUiSplitPane from "../../Ellie/Ui/SplitPane"; import EllieUiCodeEditor from "../../Ellie/Ui/CodeEditor"; import EllieUiOutput from "../../Ellie/Ui/Output"; +import EllieConstants from "../../Ellie/Constants"; import "../../Ellie/Ui/CodeEditor.css"; import "./Views/Setup.css"; import "./Main.css"; import Main from "./Main"; import { Elm } from "./Main.elm"; +__webpack_public_path__ = EllieConstants.publicPath(); + document.addEventListener("DOMContentLoaded", () => { let flags = {}; flags = Main.flags(flags); diff --git a/assets/src/Pages/Embed/index.js b/assets/src/Pages/Embed/index.js index bcb8592f..5233aafa 100644 --- a/assets/src/Pages/Embed/index.js +++ b/assets/src/Pages/Embed/index.js @@ -1,6 +1,7 @@ import EllieUiIcon from "../../Ellie/Ui/Icon"; import EllieUiCodeEditor from "../../Ellie/Ui/CodeEditor"; import EllieUiOutput from "../../Ellie/Ui/Output"; +import EllieConstants from "../../Ellie/Constants"; import NetworkAbsintheSocket from "../../Network/Absinthe/Socket"; import EffectProgram from "../../Effect/Program"; import PagesEmbedMain from "./Main"; @@ -8,6 +9,8 @@ import "../../Ellie/Ui/CodeEditor.css"; import "../../Ellie/Ui/Logo.css"; import { Elm } from "./Main.elm"; +__webpack_public_path__ = EllieConstants.publicPath(); + document.addEventListener("DOMContentLoaded", () => { let flags = {}; diff --git a/assets/webpack.dev.config.js b/assets/webpack.dev.config.js index 0f7fd468..2e5e59f9 100644 --- a/assets/webpack.dev.config.js +++ b/assets/webpack.dev.config.js @@ -21,9 +21,9 @@ module.exports = { }, output: { - path: path.resolve(__dirname, "../priv/static"), - publicPath: "http://localhost:8080/assets/", - filename: "[name].js" + path: path.resolve(__dirname + "/../priv/static"), + filename: "[name].js", + publicPath: "http://localhost:8080/assets/" }, module: { diff --git a/lib/ellie_web/endpoint.ex b/lib/ellie_web/endpoint.ex index 50fc2902..7791fca1 100644 --- a/lib/ellie_web/endpoint.ex +++ b/lib/ellie_web/endpoint.ex @@ -13,14 +13,12 @@ defmodule EllieWeb.Endpoint do plug(Phoenix.CodeReloader) end - if Application.get_env(:ellie, :env) == :prod do - plug(Plug.Static, - at: "/assets", - from: :ellie, - gzip: true, - headers: %{"Service-Worker-Allowed" => "/", "Access-Control-Allow-Origin" => "*"} - ) - end + plug(Plug.Static, + at: "/assets", + from: :ellie, + gzip: true, + headers: %{"Service-Worker-Allowed" => "/", "Access-Control-Allow-Origin" => "*"} + ) plug(Plug.Logger) diff --git a/lib/ellie_web/templates/page/editor.html.eex b/lib/ellie_web/templates/page/editor.html.eex index 70cb03bb..1dab5a27 100644 --- a/lib/ellie_web/templates/page/editor.html.eex +++ b/lib/ellie_web/templates/page/editor.html.eex @@ -2,6 +2,7 @@ + " /> " /> <%= render("polyfills.html") %> diff --git a/lib/ellie_web/templates/page/embed.html.eex b/lib/ellie_web/templates/page/embed.html.eex index 448659e8..7185e405 100644 --- a/lib/ellie_web/templates/page/embed.html.eex +++ b/lib/ellie_web/templates/page/embed.html.eex @@ -2,6 +2,7 @@ + " /> " /> <%= render("polyfills.html") %>