Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Suggestions from Upstream #6

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ import newsletters from './routes/newsletters.js';
const expressApp = express();
Miscellaneous.setup(expressApp).then();

// Middleware to provide constants to all views
expressApp.use(async (req, res, next) => {
try {
const configs = await ProjectConfigs.all();
res.locals.ghoslerUrl = configs.ghosler.url || '';
} catch (error) {
res.locals.ghoslerUrl = '';
logDebug(logTags.Express, 'Error loading configuration: ' + error.message);
}
next();
});

// define routes
logDebug('Express', 'Setting routes...');
expressApp.use(track);
Expand Down
8 changes: 5 additions & 3 deletions routes/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ router.post('/template', async (req, res) => {
router.post('/', async (req, res) => {
const formData = req.body;

let fullUrl = `${req.protocol}://${req.get('Host')}${req.originalUrl.split("/settings")[0]}`;
let fullUrl = new URL(`${req.protocol}://${req.get('Host')}${req.originalUrl}`);
if (req.get('Referer')) {
fullUrl = req.get('Referer').split("/settings")[0];
fullUrl = new URL(req.get('Referer'));
}
formData['ghosler.url'] = fullUrl;
fullUrl.pathname = fullUrl.pathname.split('/settings')[0];
fullUrl.search = ''; // drops any query parameters
formData['ghosler.url'] = fullUrl.toString();

const result = await ProjectConfigs.update(formData);
const configs = await ProjectConfigs.all();
Expand Down
11 changes: 10 additions & 1 deletion utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ export default class Miscellaneous {
expressApp.enable('trust proxy');

// add common data for response.
expressApp.use((_, res, next) => {
expressApp.use(async (_, res, next) => {
// add project version info for all render pages.
res.locals.version = ProjectConfigs.ghoslerVersion;

// add no robots header tag to all.
res.header('X-Robots-Tag', 'noindex, nofollow');

// provide ghosler.url to every view.
try {
const ghosler = await ProjectConfigs.ghosler();
res.locals.ghoslerUrl = ghosler.url || '';
} catch {
res.locals.ghoslerUrl = '';
logDebug(logTags.Express, 'Error loading ghosler.url config: ' + error.message);
}

// finally move ahead.
next();
});
Expand Down
Loading