Skip to content

Commit

Permalink
Merge pull request #6 from fritz-fritz/relative-2
Browse files Browse the repository at this point in the history
Implemented Suggestions from Upstream
  • Loading branch information
fritz-fritz authored May 31, 2024
2 parents 1fd10ac + e2c2e40 commit e558ce1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
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

0 comments on commit e558ce1

Please sign in to comment.