Server side rendering???

pull/395/head
Rick Carlino 2017-08-09 11:58:02 -05:00
parent 6a56624745
commit 2c4e1e820f
11 changed files with 66 additions and 47 deletions

View File

@ -26,7 +26,7 @@ gem "pg"
gem "polymorphic_constraints"
gem "tzinfo" # For validation of user selected timezone names
gem "foreman"
gem "webpack-rails"
# Error reporting tools.
# Active on the "official" FarmBot server, set the appropriate ENV
# vars if you wish to use them on your own servers.

View File

@ -267,6 +267,8 @@ GEM
url (0.3.2)
warden (1.2.7)
rack (>= 1.0)
webpack-rails (0.9.10)
railties (>= 3.2.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
@ -306,6 +308,7 @@ DEPENDENCIES
smarf_doc!
thin
tzinfo
webpack-rails
RUBY VERSION
ruby 2.4.1p111

View File

@ -5,8 +5,13 @@ class DashboardController < ApplicationController
THE_FRONTEND_APP = File.read(HAS_FE ? FE_PATH : FE_FALLBACK).html_safe
ACME_SECRET = ENV["ACME_SECRET"]
def index
render html: THE_FRONTEND_APP, layout: false
def main_app
# render html: THE_FRONTEND_APP, layout: false
render :main_app, layout: false
end
def front_page
render :front_page, layout: false
end
# Hit by Certbot / Let's Encrypt when it's time to verify control of domain.

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>FarmBot</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/dist/styles.css">
</head>
<body>
<%= javascript_include_tag *webpack_asset_paths("front_page") %>
</body>
</html>

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i" rel="stylesheet">
</head>
<body>
<%= javascript_include_tag *webpack_asset_paths("bundle") %>
</body>
</html>

View File

@ -11,4 +11,5 @@ FarmBot::Application.configure do
config.eager_load = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
config.webpack.public_path = nil
end

View File

@ -37,6 +37,7 @@ FarmBot::Application.routes.draw do
# You can set FORCE_SSL when you're done.
get "/.well-known/acme-challenge/:id" => "dashboard#lets_encrypt", as: :lets_encrypt
# Hacks for HTML5 push state routing:
get "/app" => 'dashboard#index', as: :dashboard
match "/app/*path", to: 'dashboard#index', via: :all # Loads /app/index.html
get "/" => 'dashboard#front_page', as: :front_page
get "/app" => 'dashboard#main_app', as: :dashboard
match "/app/*path", to: 'dashboard#main_app', via: :all
end

View File

@ -81,6 +81,7 @@
"redux-immutable-state-invariant": "^2.0.0",
"redux-thunk": "^2.0.1",
"sass-loader": "^6.0.6",
"stats-webpack-plugin": "^0.6.1",
"style-loader": "^0.18.2",
"ts-jest": "^20.0.7",
"ts-lint": "^4.5.1",

View File

@ -4,6 +4,7 @@ var exec = require("child_process").exec;
var execSync = require("child_process").execSync;
var webpack = require("webpack");
var fs = require("fs");
var StatsPlugin = require('stats-webpack-plugin');
var FarmBotRenderer = require("./farmBotRenderer");
var VERSION = JSON.stringify(process.env.BUILT_AT
@ -59,6 +60,14 @@ module.exports = function () {
// Shared plugins for prod and dev.
plugins: [
new StatsPlugin('manifest.json', {
// We only need assetsByChunkName
chunkModules: false,
source: false,
chunks: false,
modules: false,
assets: true
}),
new webpack.DefinePlugin({
"process.env.SHORT_REVISION": VERSION
}),
@ -78,46 +87,13 @@ module.exports = function () {
new webpack.DefinePlugin({
"process.env.PRIV_URL": JSON
.stringify(process.env.PRIV_URL || false).toString()
}),
new FarmBotRenderer({
isProd: isProd,
path: path.resolve(__dirname, "../webpack/static/app_index.hbs"),
filename: "index.html",
outputPath: path.resolve(__dirname, "../public/app/")
}),
new FarmBotRenderer({
isProd: isProd,
path: path.resolve(__dirname, "../webpack/static/front_page.hbs"),
filename: "index.html",
outputPath: path.resolve(__dirname, "../public/"),
include: "front_page"
}),
new FarmBotRenderer({
isProd: isProd,
path: path.resolve(__dirname, "../webpack/static/verification.hbs"),
filename: "verify.html",
outputPath: path.resolve(__dirname, "../public/"),
include: "verification"
}),
new FarmBotRenderer({
isProd: isProd,
path: path.resolve(__dirname, "../webpack/static/password_reset.hbs"),
filename: "password_reset.html",
outputPath: path.resolve(__dirname, "../public/"),
include: "password_reset"
}),
new FarmBotRenderer({
isProd: isProd,
path: path.resolve(__dirname, "../webpack/static/tos_update.hbs"),
filename: "tos_update.html",
outputPath: path.resolve(__dirname, "../public/"),
include: "tos_update"
})
],
// Webpack Dev Server.
devServer: {
port: 3808,
publicPath: "/",
historyApiFallback: {
rewrites: [
{ from: /\/app\//, to: "/app/index.html" },

View File

@ -14,4 +14,4 @@
{{/each}}
</body>
</html>
</html>

View File

@ -5251,6 +5251,12 @@ stack-trace@0.0.x:
version "0.0.9"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.9.tgz#a8f6eaeca90674c333e7c43953f275b451510695"
stats-webpack-plugin@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/stats-webpack-plugin/-/stats-webpack-plugin-0.6.1.tgz#5db260514387bc3d4ba6fb85fc4990bd4a71c415"
dependencies:
lodash "^4.17.4"
"statuses@>= 1.3.1 < 2", statuses@~1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
@ -5996,13 +6002,7 @@ which-module@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
which@1, which@^1.0.5, which@^1.2.12, which@^1.2.9:
version "1.2.14"
resolved "https://registry.yarnpkg.com/which/-/which-1.2.14.tgz#9a87c4378f03e827cecaf1acdf56c736c01c14e5"
dependencies:
isexe "^2.0.0"
which@^1.3.0:
which@1, which@^1.0.5, which@^1.2.12, which@^1.2.9, which@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
dependencies: