Browse Source

venue updates and fixes

develop
Rob Colbert 2 years ago
parent
commit
963a36b846
  1. 11
      app/controllers/venue.js
  2. 29
      app/services/venue.js
  3. 20
      app/views/components/page-sidebar.pug
  4. 3
      app/views/venue/embed.pug
  5. 11
      config/limiter.js
  6. 11
      dtp-sites.js
  7. 26
      lib/site-platform.js

11
app/controllers/venue.js

@ -15,23 +15,26 @@ class VenueController extends SiteController {
async start ( ) { async start ( ) {
const { limiter: limiterService } = this.dtp.services; const { limiter: limiterService } = this.dtp.services;
const welcomeLimiter = limiterService.createMiddleware(limiterService.config.welcome);
const router = express.Router(); const router = express.Router();
router.use(this.dtp.services.venue.channelMiddleware()); router.use(this.dtp.services.venue.channelMiddleware());
this.dtp.app.use('/venue', welcomeLimiter, async (req, res, next) => { this.dtp.app.use('/venue', async (req, res, next) => {
res.locals.currentView = 'venue'; res.locals.currentView = 'venue';
return next(); return next();
}, router); }, router);
router.get('/', this.getVenueView.bind(this)); router.get(
'/',
limiterService.createMiddleware(limiterService.config.venue.getVenueEmbed),
this.getVenueEmbed.bind(this),
);
return router; return router;
} }
async getVenueView (req, res) { async getVenueEmbed (req, res) {
res.render('venue/embed'); res.render('venue/embed');
} }
} }

29
app/services/venue.js

@ -4,6 +4,7 @@
'use strict'; 'use strict';
const https = require('https');
const fetch = require('node-fetch'); // jshint ignore:line const fetch = require('node-fetch'); // jshint ignore:line
const CACHE_DURATION = 60 * 5; const CACHE_DURATION = 60 * 5;
@ -14,6 +15,14 @@ class VenueService extends SiteService {
constructor (dtp) { constructor (dtp) {
super(dtp, module.exports); super(dtp, module.exports);
this.soapboxDomain = process.env.DTP_SOAPBOX_HOST || 'shing.tv';
}
async start ( ) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
this.httpsAgent = new https.Agent({
rejectUnauthorized: false,
});
} }
channelMiddleware ( ) { channelMiddleware ( ) {
@ -22,12 +31,12 @@ class VenueService extends SiteService {
if (!res.locals.site || !res.locals.site.shingChannelSlug) { if (!res.locals.site || !res.locals.site.shingChannelSlug) {
return next(); return next();
} }
res.locals.shingChannelFeed = await this.getChannelFeed(res.locals.site.shingChannelSlug, { allowCache: true }); res.locals.shingChannelFeed = await this.getChannelFeed(res.locals.site.shingChannelSlug, { allowCache: false });
res.locals.shingChannelStatus = await this.getChannelStatus(res.locals.site.shingChannelSlug, { allowCache: true }); res.locals.shingChannelStatus = await this.getChannelStatus(res.locals.site.shingChannelSlug, { allowCache: false });
this.log.debug('channel status', { status: res.locals.shingChannelStatus }); this.log.debug('channel status', { status: res.locals.shingChannelStatus });
return next(); return next();
} catch (error) { } catch (error) {
this.log.error('failed to populate Shing.tv channel feed', { error }); this.log.error('failed to populate Soapbox channel feed', { error });
return next(); return next();
} }
}; };
@ -44,8 +53,11 @@ class VenueService extends SiteService {
if (json) { return json; } if (json) { return json; }
} }
this.log.info('fetching Shing channel feed', { channelSlug }); const requestUrl = `https://${this.soapboxDomain}/channel/${channelSlug}/feed/json`;
const response = await fetch(`https://shing.tv/channel/${channelSlug}/feed/json`); this.log.info('fetching Shing channel feed', { channelSlug, requestUrl });
const response = await fetch(requestUrl, {
agent: this.httpsAgent,
});
if (!response.ok) { if (!response.ok) {
throw new SiteError(500, 'Failed to fetch Shing channel feed'); throw new SiteError(500, 'Failed to fetch Shing channel feed');
} }
@ -67,8 +79,11 @@ class VenueService extends SiteService {
if (json) { return json; } if (json) { return json; }
} }
this.log.info('fetching Shing channel status', { channelSlug }); const requestUrl = `https://${this.soapboxDomain}/channel/${channelSlug}/status`;
const response = await fetch(`https://shing.tv/channel/${channelSlug}/status`); this.log.info('fetching Shing channel status', { channelSlug, requestUrl });
const response = await fetch(requestUrl, {
agent: this.httpsAgent,
});
if (!response.ok) { if (!response.ok) {
throw new SiteError(500, 'Failed to fetch Shing channel status'); throw new SiteError(500, 'Failed to fetch Shing channel status');
} }

20
app/views/components/page-sidebar.pug

@ -9,10 +9,14 @@ mixin renderSidebarEpisode(episode)
a(href= episode.url, target="_blank", title="Watch on Gab TV") a(href= episode.url, target="_blank", title="Watch on Gab TV")
img(src=episode.image).responsive img(src=episode.image).responsive
.uk-card-body a(
.uk-card-title.uk-margin-remove.uk-text-truncate href= episode.url,
a(href= episode.url, target="_blank", title= `Watch "${episode.title}" on Gab TV`)= episode.title uk-tooltip=`Watch ${episode.title} on Gab TV`,
.uk-text-small Posted: #{moment(episode.date_modified).format("MMM DD YYYY HH:MM a")} target="_blank",
).uk-link-reset.uk-display-block
.uk-card-body
.uk-text-bold.uk-text-truncate= episode.title
.uk-text-small= moment(episode.date_modified).format("MMM DD YYYY HH:MM a")
mixin renderPageSidebar ( ) mixin renderPageSidebar ( )
//- //-
@ -64,12 +68,14 @@ mixin renderPageSidebar ( )
ul.uk-list ul.uk-list
each item in shingChannelFeed.items.slice(0, 3) each item in shingChannelFeed.items.slice(0, 3)
li li
a(href= item.url).uk-display-block a(href= item.url, uk-tooltip=`Watch ${item.title} on Shing.tv`).uk-link-reset.uk-display-block
.uk-card.uk-card-default.uk-card-small .uk-card.uk-card-default.uk-card-small
img(src= item.image.url).responsive img(src= item.image.url, width="640", height="360", alt=`Thumbnail image for ${item.title}`).responsive
.uk-card-body .uk-card-body
.uk-text-bold.uk-text-truncate= item.title .uk-text-bold.uk-text-truncate= item.title
.uk-text-small!= item.summary .uk-text-small= moment(item.date_modified).format("MMM DD YYYY hh:mm a")
//- .uk-text-small!= item.summary
pre= JSON.stringify(item, null, 2)
//- //-
//- Gab TV channel integration //- Gab TV channel integration
//- //-

3
app/views/venue/embed.pug

@ -1,6 +1,5 @@
extends ../layouts/main extends ../layouts/main
block content block content
//- - var shingBaseUrl = (process.env.NODE_ENV === 'production') ? 'https://shing.tv' : 'http://localhost:3333'; - var shingBaseUrl = `https://${dtp.services.venue.soapboxDomain}`;
- var shingBaseUrl = 'https://shing.tv';
iframe(src= `${shingBaseUrl}/channel/${site.shingChannelSlug}/embed/venue?k=${site.shingWidgetKey}`, style="width: 100%; height: 720px;", allowfullscreen) iframe(src= `${shingBaseUrl}/channel/${site.shingChannelSlug}/embed/venue?k=${site.shingWidgetKey}`, style="width: 100%; height: 720px;", allowfullscreen)

11
config/limiter.js

@ -353,6 +353,17 @@ module.exports = {
}, },
}, },
/*
* VenueController
*/
venue: {
getVenueEmbed: {
total: 20,
expire: ONE_MINUTE,
message: 'You are loading Venue too quickly. Please try again later.',
},
},
welcome: { welcome: {
total: 12, total: 12,
expire: ONE_MINUTE, expire: ONE_MINUTE,

11
dtp-sites.js

@ -16,11 +16,18 @@ module.rootPath = __dirname;
module.pkg = require(path.join(module.rootPath, 'package.json')); module.pkg = require(path.join(module.rootPath, 'package.json'));
module.config = { module.config = {
environment: process.env.NODE_ENV, environment: process.env.NODE_ENV,
root: module.rootPath,
component: DTP_COMPONENT, component: DTP_COMPONENT,
root: module.rootPath,
site: require(path.join(module.rootPath, 'config', 'site')), site: require(path.join(module.rootPath, 'config', 'site')),
http: require(path.join(module.rootPath, 'config', 'http')), http: require(path.join(module.rootPath, 'config', 'http')),
https: require(path.join(module.rootPath, 'config', 'https')), https: require(path.join(module.rootPath, 'config', 'https')),
registerMiddleware: async (dtp, app) => {
module.log.info('registering Page service middleware');
const { page: pageService } = module.services;
app.use(pageService.menuMiddleware.bind(pageService));
},
}; };
module.log = new SiteLog(module, module.config.component); module.log = new SiteLog(module, module.config.component);
@ -66,4 +73,4 @@ module.shutdown = async ( ) => {
process.exit(-1); process.exit(-1);
} }
})(); })();

26
lib/site-platform.js

@ -202,7 +202,6 @@ module.exports.startPlatform = async (dtp) => {
}; };
module.exports.startWebServer = async (dtp) => { module.exports.startWebServer = async (dtp) => {
const { page: pageService } = module.services;
const IS_PRODUCTION = (process.env.NODE_ENV === 'production'); const IS_PRODUCTION = (process.env.NODE_ENV === 'production');
dtp.app = module.app = express(); dtp.app = module.app = express();
@ -343,9 +342,7 @@ module.exports.startWebServer = async (dtp) => {
module.app.use(async (req, res, next) => { module.app.use(async (req, res, next) => {
const { cache: cacheService } = dtp.services; const { cache: cacheService } = dtp.services;
try { try {
res.locals.dtp = { // expect incoming change from Base
request: req,
};
const settingsKey = `settings:${dtp.config.site.domainKey}:site`; const settingsKey = `settings:${dtp.config.site.domainKey}:site`;
res.locals.site = Object.assign({ }, dtp.config.site); res.locals.site = Object.assign({ }, dtp.config.site);
@ -360,7 +357,6 @@ module.exports.startWebServer = async (dtp) => {
return next(error); return next(error);
} }
}); });
module.app.use(pageService.menuMiddleware.bind(pageService));
/* /*
* System Init * System Init
@ -385,12 +381,7 @@ module.exports.startWebServer = async (dtp) => {
if (process.env.HTTP_ENABLE === 'enabled') { if (process.env.HTTP_ENABLE === 'enabled') {
if (process.env.HTTP_REDIRECT_SSL === 'enabled') { if (process.env.HTTP_REDIRECT_SSL === 'enabled') {
module.log.info('creating HTTP SSL redirect app'); await module.createSslRedirectApp(dtp);
module.redirectApp = express();
module.redirectApp.use((req, res) => {
module.log.info('redirecting to SSL', { host: req.host, url: req.url });
res.redirect(`https://${process.env.DTP_SITE_DOMAIN}${req.url}`);
});
await module.createHttpServer(dtp, module.redirectApp); await module.createHttpServer(dtp, module.redirectApp);
} else { } else {
await module.createHttpServer(dtp, module.app); await module.createHttpServer(dtp, module.app);
@ -437,6 +428,19 @@ module.createHttpsServer = async (dtp, app) => {
return module.https; return module.https;
}; };
module.createSslRedirectApp = async (/* dtp */) => {
module.log.info('creating HTTP SSL redirect app');
module.redirectApp = express();
module.redirectApp.use((req, res) => {
module.log.info('redirecting to SSL', { host: req.host, url: req.url });
res.redirect(`https://${process.env.DTP_SITE_DOMAIN}${req.url}`);
});
return module.redirectApp;
};
module.startHttpServer = async (dtp, server, config) => { module.startHttpServer = async (dtp, server, config) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
module.log.info('starting HTTP server', { port: config.port, bind: config.address }); module.log.info('starting HTTP server', { port: config.port, bind: config.address });

Loading…
Cancel
Save