mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 07:32:40 +00:00
Update app.js
This commit is contained in:
@@ -8,6 +8,7 @@ const express = require('express');
|
|||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
const app = express();
|
const app = express();
|
||||||
const config = require('./config.js');
|
const config = require('./config.js');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js');
|
const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js');
|
||||||
const GoogleActions = require('./googleActions.js');
|
const GoogleActions = require('./googleActions.js');
|
||||||
@@ -204,6 +205,23 @@ app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{
|
|||||||
res.status(200).send(brew.text);
|
res.status(200).send(brew.text);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Serve brew metadata
|
||||||
|
app.get('/metadata/:id', asyncHandler(getBrew('share')), (req, res)=>{
|
||||||
|
const { brew } = req;
|
||||||
|
sanitizeBrew(brew, 'share');
|
||||||
|
|
||||||
|
const fields = ['title', 'pageCount', 'description', 'authors', 'lang',
|
||||||
|
'published', 'views', 'shareId', 'createdAt', 'updatedAt',
|
||||||
|
'lastViewed', 'thumbnail', 'tags'
|
||||||
|
];
|
||||||
|
|
||||||
|
const metadata = fields.reduce((acc, field)=>{
|
||||||
|
if(brew[field] !== undefined) acc[field] = brew[field];
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
res.status(200).json(metadata);
|
||||||
|
});
|
||||||
|
|
||||||
//Serve brew styling
|
//Serve brew styling
|
||||||
app.get('/css/:id', asyncHandler(getBrew('share')), (req, res)=>{getCSS(req, res);});
|
app.get('/css/:id', asyncHandler(getBrew('share')), (req, res)=>{getCSS(req, res);});
|
||||||
|
|
||||||
@@ -429,8 +447,16 @@ if(isLocalEnvironment){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add Static Local Paths
|
||||||
|
app.use('/staticImages', express.static(config.get('hb_images') && fs.existsSync(config.get('hb_images')) ? config.get('hb_images') :'staticImages'));
|
||||||
|
app.use('/staticFonts', express.static(config.get('hb_fonts') && fs.existsSync(config.get('hb_fonts')) ? config.get('hb_fonts'):'staticFonts'));
|
||||||
|
|
||||||
//Vault Page
|
//Vault Page
|
||||||
app.get('/vault', asyncHandler(async(req, res, next)=>{
|
app.get('/vault', asyncHandler(async(req, res, next)=>{
|
||||||
|
req.ogMeta = { ...defaultMetaTags,
|
||||||
|
title : 'The Vault',
|
||||||
|
description : 'Search for Brews'
|
||||||
|
};
|
||||||
return next();
|
return next();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user