diff --git a/client/coral-admin/src/routes/Configure/components/EmbedLink.js b/client/coral-admin/src/routes/Configure/components/EmbedLink.js index aa1cddadc..fb7571711 100644 --- a/client/coral-admin/src/routes/Configure/components/EmbedLink.js +++ b/client/coral-admin/src/routes/Configure/components/EmbedLink.js @@ -5,6 +5,7 @@ import styles from './EmbedLink.css'; import {Button} from 'coral-ui'; import {BASE_URL} from 'coral-framework/constants/url'; import ConfigureCard from 'coral-framework/components/ConfigureCard'; +import {stripIndent} from 'common-tags'; class EmbedLink extends Component { @@ -23,17 +24,16 @@ class EmbedLink extends Component { } render () { - const coralJsUrl = join(BASE_URL, '/embed.js'); - const nonce = String(Math.random()).slice(2); - const streamElementId = `coral_talk_${nonce}`; - const embedText = ` -
- - `.trim(); + const coralJsUrl = join(BASE_URL, '/static/embed.js'); + const embedText = stripIndent` + + + `; + return ({t('configure.copy_and_paste')}
diff --git a/client/coral-framework/services/i18n.js b/client/coral-framework/services/i18n.js index 7afb16860..0fb4cd543 100644 --- a/client/coral-framework/services/i18n.js +++ b/client/coral-framework/services/i18n.js @@ -3,6 +3,11 @@ import has from 'lodash/has'; import get from 'lodash/get'; import merge from 'lodash/merge'; +import 'moment/locale/da'; +import 'moment/locale/es'; +import 'moment/locale/fr'; +import 'moment/locale/pt-br'; + import daTA from 'timeago.js/locales/da'; import esTA from 'timeago.js/locales/es'; import frTA from 'timeago.js/locales/fr'; diff --git a/package.json b/package.json index 7ddcac180..3e948cb32 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "bcryptjs": "^2.4.3", "body-parser": "1.18.2", "bowser": "^1.7.2", + "brotli-webpack-plugin": "^0.5.0", "cli-table": "^0.3.1", "clipboard": "^1.7.1", "colors": "^1.1.2", @@ -91,6 +92,7 @@ "eventemitter2": "^4.1.2", "exports-loader": "^0.6.4", "express": "4.16.0", + "express-static-gzip": "^0.3.1", "file-loader": "^0.11.2", "form-data": "^2.3.1", "fs-extra": "^4.0.1", @@ -117,7 +119,6 @@ "jwt-decode": "^2.2.0", "keymaster": "^1.6.2", "kue": "0.11.6", - "license-webpack-plugin": "^1.0.0", "linkify-it": "^2.0.3", "lodash": "^4.16.6", "marked": "^0.3.6", diff --git a/routes/index.js b/routes/index.js index 848269a4d..90654adc5 100644 --- a/routes/index.js +++ b/routes/index.js @@ -9,10 +9,10 @@ const i18n = require('../services/i18n'); const enabled = require('debug').enabled; const errors = require('../errors'); const {createGraphOptions} = require('../graph'); -const accepts = require('accepts'); const apollo = require('graphql-server-express'); const {DISABLE_STATIC_SERVER} = require('../config'); const SetupService = require('../services/setup'); +const static = require('express-static-gzip'); const router = express.Router(); @@ -22,44 +22,20 @@ const router = express.Router(); if (!DISABLE_STATIC_SERVER) { - // If the application is in production mode, then add gzip rewriting for the - // content. - if (process.env.NODE_ENV === 'production') { - router.get('*.js', (req, res, next) => { - const accept = accepts(req); - if (accept.encoding(['gzip']) === 'gzip') { - - // Adjust the headers on the request by adding a content type header - // because express won't be able to detect the mime-type with the .gz - // extension and we need to declare support for the gzip encoding. - res.set('Content-Type', 'application/javascript'); - res.set('Content-Encoding', 'gzip'); - - // Rewrite the url so that the gzip version will be served instead. - req.url = `${req.url}.gz`; - } - - next(); - }); - } - /** * Serve the directories under public/dist from this router. */ - router.use('/client', express.static(path.join(__dirname, '../dist'))); router.use('/public', express.static(path.join(__dirname, '../public'))); - - /** - * Serves a file based on a relative path. - */ - const serveFile = (filename) => (req, res) => res.sendFile(path.join(__dirname, filename)); - - /** - * Serves the embed javascript files. - */ - router.get('/embed.js', serveFile('../dist/embed.js')); - router.get('/embed.js.gz', serveFile('../dist/embed.js.gz')); - router.get('/embed.js.map', serveFile('../dist/embed.js.map')); + router.use('/static', static(path.resolve(path.join(__dirname, '../dist')), { + indexFromEmptyFile: false, + enableBrotli: true, + customCompressions: [ + { + encodingName: 'deflate', + fileExtension: 'zz', + }, + ], + })); } //============================================================================== @@ -129,7 +105,7 @@ if (process.env.NODE_ENV !== 'production') { asset_url: '', asset_id: '', body: '', - basePath: '/client/embed/stream' + basePath: '/static/embed/stream' }); } }); diff --git a/views/admin.ejs b/views/admin.ejs index 70fed054e..9bbee7e32 100644 --- a/views/admin.ejs +++ b/views/admin.ejs @@ -42,6 +42,6 @@ - +