Skip to content

Commit

Permalink
Switch to serialize-javascript for injecting props.
Browse files Browse the repository at this point in the history
  • Loading branch information
phulin committed Jan 20, 2020
1 parent 7e869cb commit 2dce8fc
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 24 deletions.
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"rss": "^1.2.2",
"sanitize-html": "^1.20.1",
"selenium-webdriver": "^4.0.0-alpha.4",
"serialize-javascript": "^2.1.2",
"serve-favicon": "^2.5.0",
"shuffle-seed": "^1.1.6",
"website-scraper": "^4.0.1",
Expand Down
23 changes: 12 additions & 11 deletions routes/cube_routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const serialize = require('serialize-javascript');
var {
addAutocard,
generatePack,
Expand Down Expand Up @@ -480,7 +481,7 @@ router.get('/overview/:id', async (req, res) => {
};

return res.render('cube/cube_overview', {
reactProps,
reactProps: serialize(reactProps),
cube,
cube_id,
title: `${abbreviate(cube.name)} - Overview`,
Expand Down Expand Up @@ -722,7 +723,7 @@ router.get('/compare/:id_a/to/:id_b', async (req, res) => {
};

params = {
reactProps,
reactProps: serialize(reactProps),
title: `Comparing ${cubeA.name} to ${cubeB.name}`,
metadata: generateMeta(
'Cube Cobra Compare Cubes',
Expand Down Expand Up @@ -790,7 +791,7 @@ router.get('/list/:id', async function(req, res) {
reactHTML: CubeListPage
? await ReactDOMServer.renderToString(React.createElement(CubeListPage, reactProps))
: undefined,
reactProps,
reactProps: serialize(reactProps),
cube,
cube_id: req.params.id,
activeLink: 'list',
Expand Down Expand Up @@ -851,7 +852,7 @@ router.get('/playtest/:id', async (req, res) => {
reactHTML: CubePlaytestPage
? await ReactDOMServer.renderToString(React.createElement(CubePlaytestPage, reactProps))
: undefined,
reactProps,
reactProps: serialize(reactProps),
cube: cube,
cube_id: req.params.id,
activeLink: 'playtest',
Expand Down Expand Up @@ -1051,7 +1052,7 @@ router.post('/importcubetutor/:id', ensureAuth, async (req, res) => {
NODE_ENV === 'production'
? await ReactDOMServer.renderToString(React.createElement(BulkUploadPage, reactProps))
: undefined,
reactProps,
reactProps: serialize(reactProps),
cube: cube,
cube_id: req.params.id,
title: `${abbreviate(cube.name)} - Bulk Upload`,
Expand Down Expand Up @@ -1276,7 +1277,7 @@ async function bulkuploadCSV(req, res, cards, cube) {
NODE_ENV === 'production'
? await ReactDOMServer.renderToString(React.createElement(BulkUploadPage, reactProps))
: undefined,
reactProps,
reactProps: serialize(reactProps),
cube: cube,
cube_id: req.params.id,
title: `${abbreviate(cube.name)} - Bulk Upload`,
Expand Down Expand Up @@ -1388,7 +1389,7 @@ async function bulkUpload(req, res, list, cube) {
reactHTML: BulkUploadPage
? await ReactDOMServer.renderToString(React.createElement(BulkUploadPage, reactProps))
: undefined,
reactProps,
reactProps: serialize(reactProps),
cube: cube,
cube_id: req.params.id,
title: `${abbreviate(cube.name)} - Bulk Upload`,
Expand Down Expand Up @@ -1627,7 +1628,7 @@ router.get('/draft/:id', async (req, res) => {
reactHTML: DraftView
? await ReactDOMServer.renderToString(React.createElement(DraftView, reactProps))
: undefined,
reactProps,
reactProps: serialize(reactProps),
title: `${abbreviate(cube.name)} - Draft`,
metadata: generateMeta(
`Cube Cobra Draft: ${cube.name}`,
Expand Down Expand Up @@ -2526,7 +2527,7 @@ router.get('/deckbuilder/:id', async (req, res) => {
};

return res.render('cube/cube_deckbuilder', {
reactProps,
reactProps: serialize(reactProps),
activeLink: 'playtest',
title: `${abbreviate(cube.name)} - Deckbuilder`,
metadata: generateMeta(
Expand Down Expand Up @@ -2631,7 +2632,7 @@ router.get('/deck/:id', async (req, res) => {
};

return res.render('cube/cube_deck', {
reactProps,
reactProps: serialize(reactProps),
title: `${abbreviate(cube.name)} - ${drafter.name}'s deck`,
metadata: generateMeta(
`Cube Cobra Deck: ${cube.name}`,
Expand Down Expand Up @@ -2680,7 +2681,7 @@ router.get('/deck/:id', async (req, res) => {
};

return res.render('cube/cube_deck', {
reactProps,
reactProps: serialize(reactProps),
title: `${abbreviate(cube.name)} - ${drafter.name}'s deck`,
metadata: generateMeta(
`Cube Cobra Deck: ${cube.name}`,
Expand Down
2 changes: 1 addition & 1 deletion views/cube/bulk_upload.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ block scripts
include ../react
script(src='/js/autocard.js')
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};
script(src='/js/bulk_upload.bundle.js')
2 changes: 1 addition & 1 deletion views/cube/cube_compare.pug
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ block scripts
include ../react
script(src='/js/autocard.js')
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};
script(src='/js/cube_compare.bundle.js')
2 changes: 1 addition & 1 deletion views/cube/cube_deck.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ block content
block scripts
script(src='/js/autocard.js')
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};
include ../react
script(src='/js/cube_deck.bundle.js')
2 changes: 1 addition & 1 deletion views/cube/cube_deckbuilder.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ block content
block scripts
script(src='/js/autocard.js')
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};
include ../react
script(src='/js/cube_deckbuilder.bundle.js')
2 changes: 1 addition & 1 deletion views/cube/cube_draft.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ block scripts
include ../react
script(src='/js/autocard.js')
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};
script(src='/js/cube_draft.bundle.js')
2 changes: 1 addition & 1 deletion views/cube/cube_list.pug
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ block content
block scripts
script(src='/js/autocard.js', async)
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};
script(src='/js/cube_list.bundle.js', async)
2 changes: 1 addition & 1 deletion views/cube/cube_overview.pug
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ block cube_content
block scripts
include ../react
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};

script(src='/js/cube_overview.bundle.js')

Expand Down
2 changes: 1 addition & 1 deletion views/cube/cube_playtest.pug
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ block cube_content
block scripts
include ../react
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};
script(src='/js/cube_playtest.bundle.js')
2 changes: 1 addition & 1 deletion views/dashboard.pug
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ block content
block scripts
include react
script(type='text/javascript').
var reactProps = !{JSON.stringify(reactProps)};
var reactProps = !{reactProps};
script(src='/js/dashboard.bundle.js')

0 comments on commit 2dce8fc

Please sign in to comment.