From 1ad7c60b1afb9fafcbd472ea6aada8e0468eb2a3 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 29 Mar 2018 09:48:32 -0700 Subject: [PATCH] updated page routes --- server/routes/fallback/fallback-routes.js | 9 ------ server/routes/page/index.js | 11 +++++++ server/routes/page/page-routes.js | 35 ----------------------- server/routes/page/redirect.js | 7 +++++ server/routes/page/sendEmbedPage.js | 12 ++++++++ server/routes/page/sendReactApp.js | 9 ++++++ speech.js | 2 ++ 7 files changed, 41 insertions(+), 44 deletions(-) delete mode 100644 server/routes/fallback/fallback-routes.js create mode 100644 server/routes/page/index.js delete mode 100644 server/routes/page/page-routes.js create mode 100644 server/routes/page/redirect.js create mode 100644 server/routes/page/sendEmbedPage.js create mode 100644 server/routes/page/sendReactApp.js diff --git a/server/routes/fallback/fallback-routes.js b/server/routes/fallback/fallback-routes.js deleted file mode 100644 index 01d1e7f0..00000000 --- a/server/routes/fallback/fallback-routes.js +++ /dev/null @@ -1,9 +0,0 @@ -const handlePageRender = require('../../helpers/handlePageRender.jsx'); - -module.exports = app => { - // a catch-all route if someone visits a page that does not exist - app.use('*', (req, res) => { - // send response - handlePageRender(req, res); - }); -}; diff --git a/server/routes/page/index.js b/server/routes/page/index.js new file mode 100644 index 00000000..63d73e34 --- /dev/null +++ b/server/routes/page/index.js @@ -0,0 +1,11 @@ +const sendReactApp = require('./sendReactApp'); +const sendEmbedPage = require('./sendEmbedPage'); +const redirect = require('./redirect'); + + + +module.exports = { + sendReactApp, + sendEmbedPage, + redirect, +}; diff --git a/server/routes/page/page-routes.js b/server/routes/page/page-routes.js deleted file mode 100644 index 6bbdafa3..00000000 --- a/server/routes/page/page-routes.js +++ /dev/null @@ -1,35 +0,0 @@ -const { details: host } = require('../../../config/siteConfig.js'); -const handlePageRender = require('../../helpers/handlePageRender.jsx'); - -module.exports = (app) => { - // route for the home page - app.get('/', (req, res) => { - handlePageRender(req, res); - }); - // route to display login page - app.get('/login', (req, res) => { - handlePageRender(req, res); - }); - // route to show 'about' page - app.get('/about', (req, res) => { - handlePageRender(req, res); - }); - // route to display a list of the trending images - app.get('/trending', (req, res) => { - res.status(301).redirect('/popular'); - }); - app.get('/popular', (req, res) => { - handlePageRender(req, res); - }); - // route to display a list of the trending images - app.get('/new', (req, res) => { - handlePageRender(req, res); - }); - // route to send embedable video player (for twitter) - app.get('/embed/:claimId/:name', ({ params }, res) => { - const claimId = params.claimId; - const name = params.name; - // get and render the content - res.status(200).render('embed', { layout: 'embed', host, claimId, name }); - }); -}; diff --git a/server/routes/page/redirect.js b/server/routes/page/redirect.js new file mode 100644 index 00000000..8f2df4dd --- /dev/null +++ b/server/routes/page/redirect.js @@ -0,0 +1,7 @@ +const redirect = (route) => { + return (req, res) => { + res.status(301).redirect(route); + }; +}; + +module.exports = redirect; diff --git a/server/routes/page/sendEmbedPage.js b/server/routes/page/sendEmbedPage.js new file mode 100644 index 00000000..e1869173 --- /dev/null +++ b/server/routes/page/sendEmbedPage.js @@ -0,0 +1,12 @@ +const { details: { host } } = require('siteConfig.js'); + +const sendEmbedPage = () => { + return ({ params }, res) => { + const claimId = params.claimId; + const name = params.name; + // get and render the content + res.status(200).render('embed', { layout: 'embed', host, claimId, name }); + }; +}; + +module.exports = sendEmbedPage; diff --git a/server/routes/page/sendReactApp.js b/server/routes/page/sendReactApp.js new file mode 100644 index 00000000..ea6fa019 --- /dev/null +++ b/server/routes/page/sendReactApp.js @@ -0,0 +1,9 @@ +const handlePageRender = require('helpers/handlePageRender.jsx'); + +const sendReactApp = () => { + return (req, res) => { + handlePageRender(req, res); + }; +}; + +module.exports = sendReactApp; diff --git a/speech.js b/speech.js index 22745cab..4ac2a562 100644 --- a/speech.js +++ b/speech.js @@ -1,6 +1,7 @@ const api = require('./server/routes/api/'); const asset = require('./server/routes/asset/'); const auth = require('./server/routes/auth/'); +const fallback = require('./server/routes/fallback'); const logger = require('./config/loggerConfig.js'); const mysql = require('./config/mysqlConfig'); const site = require('./config/siteConfig'); @@ -20,6 +21,7 @@ const exports = { api, asset, auth, + fallback, }, // Components, };