diff --git a/client/components/Nav.jsx b/client/components/Nav.jsx index f5014774..07aee20f 100644 --- a/client/components/Nav.jsx +++ b/client/components/Nav.jsx @@ -219,6 +219,7 @@ class Nav extends React.PureComponent { Open } + { __process.env.EXAMPLES_ENABLED &&
  • Examples -
  • + }
  • diff --git a/server/views/404Page.js b/server/views/404Page.js index 10e705e7..77666f9a 100644 --- a/server/views/404Page.js +++ b/server/views/404Page.js @@ -1,11 +1,77 @@ import User from '../models/user'; import Project from '../models/project'; +function insertErrorMessage(htmlFile) { + const html = htmlFile.split(''); + const metaDescription = 'A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.'; // eslint-disable-line + html[0] = ` + ${html[0]} + + + + + 404 Page Not Found - p5.js Web Editor + + + + + `; + const body = html[1].split(''); + html[1] = ` + ${body[0]} + +
    +
    +

    404 Page Not Found

    +
    The page you are trying to reach does not exist.
    +
    + Please check the URL or return to the home page. +
    +
    +
    + ${body[1]} + `; + return html.join(''); +} + export function get404Sketch(callback) { User.findOne({ username: 'p5' }, (userErr, user) => { // Find p5 user if (userErr) { throw userErr; - } else { + } else if (user) { Project.find({ user: user._id }, (projErr, projects) => { // Find example projects // Choose a random sketch const randomIndex = Math.floor(Math.random() * projects.length); @@ -39,66 +105,7 @@ export function get404Sketch(callback) { }); // Add 404 html and position canvas - const html = htmlFile.split(''); - const metaDescription = 'A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.'; // eslint-disable-line - html[0] = ` - ${html[0]} - - - - - 404 Page Not Found - p5.js Web Editor - - - - - `; - html[1] = ` -
    -
    -

    404 Page Not Found

    -
    The page you are trying to reach does not exist.
    -
    - Please check the URL or return to the home page. -
    -
    -
    - ${html[1]} - `; - htmlFile = html.join(''); + htmlFile = insertErrorMessage(htmlFile); // Fix links to assets htmlFile = htmlFile.replace( @@ -118,9 +125,17 @@ export function get404Sketch(callback) { callback(htmlFile); }); + } else { + callback(insertErrorMessage(` + + + + + + + `)); } }); } export default get404Sketch; - diff --git a/server/views/index.js b/server/views/index.js index 3da61085..d4062061 100644 --- a/server/views/index.js +++ b/server/views/index.js @@ -28,7 +28,8 @@ export function renderIndex() { window.process.env.AWS_REGION = '${process.env.AWS_REGION}'; window.process.env.FORCE_TO_HTTPS = ${process.env.FORCE_TO_HTTPS === 'false' ? false : undefined}; window.process.env.CLIENT = true; - window.process.env.LOGIN_ENABLED = ${process.env.LOGIN_ENABLED === 'false' ? false : true} + window.process.env.LOGIN_ENABLED = ${process.env.LOGIN_ENABLED === 'false' ? false : true}; + window.process.env.EXAMPLES_ENABLED = ${process.env.EXAMPLES_ENABLED === 'false' ? false : true};