From d4560905eddb2f5434534cd49056ec429e4a8f55 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 5 Jul 2017 12:23:55 -0700 Subject: [PATCH] build the handlebars template and serve/show route fork --- routes/serve-routes.js | 32 +++++++++++++++++++++---- views/partials/asset.handlebars | 4 ++++ views/partials/assetLinks.handlebars | 4 ++++ views/partials/assetMetadata.handlebars | 4 ++++ views/show.handlebars | 14 +++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 views/partials/asset.handlebars create mode 100644 views/partials/assetLinks.handlebars create mode 100644 views/partials/assetMetadata.handlebars create mode 100644 views/show.handlebars diff --git a/routes/serve-routes.js b/routes/serve-routes.js index fee6b68f..124c1ac2 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -32,7 +32,17 @@ function serveFile ({ fileName, fileType, filePath }, res) { res.status(200).sendFile(filePath, options); } +function servePage ({ fileName, fileType, filePath }, res) { + logger.info(`serving show page for ${fileName}`); + // set default options + let showOptions; + + // send file + res.status(200).render('show', showOptions); +} + function sendAnalyticsAndLog (headers, ip, originalUrl) { + logger.verbose('headers', headers); // google analytics sendGoogleAnalytics('serve', headers, ip, originalUrl); // logging @@ -52,8 +62,15 @@ module.exports = (app) => { res.status(307).render('noClaims'); return; } - postToStats('serve', originalUrl, ip, 'success'); - serveFile(fileInfo, res); + // serve the file or the show route + const mimetypes = headers['accept'].split(','); + if (mimetypes.includes('text/html')) { + postToStats('show', originalUrl, ip, 'success'); + servePage(fileInfo, res); + } else { + postToStats('serve', originalUrl, ip, 'success'); + serveFile(fileInfo, res); + } }) .catch(error => { errorHandlers.handleRequestError('serve', originalUrl, ip, error, res); @@ -71,8 +88,15 @@ module.exports = (app) => { res.status(307).render('noClaims'); return; } - postToStats('serve', originalUrl, ip, 'success'); - serveFile(fileInfo, res); + // serve the file or the show route + const mimetypes = headers['accept'].split(','); + if (mimetypes.includes('text/html')) { + postToStats('show', originalUrl, ip, 'success'); + servePage(fileInfo, res); + } else { + postToStats('serve', originalUrl, ip, 'success'); + serveFile(fileInfo, res); + } }) .catch(error => { errorHandlers.handleRequestError('serve', originalUrl, ip, error, res); diff --git a/views/partials/asset.handlebars b/views/partials/asset.handlebars new file mode 100644 index 00000000..79158d4a --- /dev/null +++ b/views/partials/asset.handlebars @@ -0,0 +1,4 @@ +
+

asset goes here

+ +
\ No newline at end of file diff --git a/views/partials/assetLinks.handlebars b/views/partials/assetLinks.handlebars new file mode 100644 index 00000000..99ad20c4 --- /dev/null +++ b/views/partials/assetLinks.handlebars @@ -0,0 +1,4 @@ +
+

links

+

links go here

+
\ No newline at end of file diff --git a/views/partials/assetMetadata.handlebars b/views/partials/assetMetadata.handlebars new file mode 100644 index 00000000..6dd584d1 --- /dev/null +++ b/views/partials/assetMetadata.handlebars @@ -0,0 +1,4 @@ +
+

metadata

+

metadata goes here

+
\ No newline at end of file diff --git a/views/show.handlebars b/views/show.handlebars new file mode 100644 index 00000000..a60ff292 --- /dev/null +++ b/views/show.handlebars @@ -0,0 +1,14 @@ +
+ {{> topBar}} +
+ {{> asset}} +
+ + {{> footer}} +
+ + + \ No newline at end of file