Skip to content

Commit

Permalink
fix(*): set public path dynamically to fetch from cdn (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbash authored Feb 2, 2019
1 parent c8b6990 commit e311b93
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions assets/src/Ellie/Constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
publicPath: () => {
return document.head.querySelector("meta[name='public_path']").content;
}
};
3 changes: 3 additions & 0 deletions assets/src/Pages/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions assets/src/Pages/Embed/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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";
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 = {};

Expand Down
6 changes: 3 additions & 3 deletions assets/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
14 changes: 6 additions & 8 deletions lib/ellie_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions lib/ellie_web/templates/page/editor.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="public_path" content="<%= static_url(@conn, "/assets/") %>" />
<link rel="icon" href="<%= static_url(@conn, "/assets/images/favicon.ico") %>" />
<link rel="alternate" type="application/json+oembed" href="<%= oembed_url(@conn) %>" />
<%= render("polyfills.html") %>
Expand Down
1 change: 1 addition & 0 deletions lib/ellie_web/templates/page/embed.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="public_path" content="<%= static_url(@conn, "/assets/") %>" />
<link rel="icon" href="<%= static_url(@conn, "/assets/images/favicon.ico") %>" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<%= render("polyfills.html") %>
Expand Down

0 comments on commit e311b93

Please sign in to comment.