Skip to content

Commit

Permalink
Allow visitors to choose an environment by passing an env query par…
Browse files Browse the repository at this point in the history
…am. (#440)

* Allow visitors to choose an environment by passing an `env` query param.

* Reconstruct entire URL and refactor a bit

* Capitalize environment name

* Undo formatting
  • Loading branch information
ChrisAntaki authored Dec 18, 2023
1 parent 287ef8a commit ffa9142
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
30 changes: 30 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ if (console.log) {
console.log('Scenic started. Publication: ' + getConfig().publicationId);
}

/**
* Allow visitors to choose an environment by passing an `env` query param.
*/
app.use((req, res, next) => {
const env = req.query.env;

// Skip, if `env` query param is missing or invalid.
if (!['prod', 'qual'].includes(env)) {
next();
return;
}

// Update `script` cookie.
res.clearCookie('script');
res.cookie('script', env);

// Remove `env` param from URL.
const params = new URLSearchParams(req.query);
params.delete('env');
const protocol = req.protocol;
const host = req.get('host');
const path = req.path;
const query = params
.toString()
// Remove trailing `=` character.
.replace(/\=$/, '');
const url = `${protocol}://${host}${path}?${query}`;
res.redirect(url);
});

/**
* List all Articles.
*/
Expand Down
4 changes: 0 additions & 4 deletions app/views/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
background: lightyellow;
padding: 16px;
}
.comments {
font-size: 8px;
margin: 16px;
}
</style>

<script type="application/ld+json">
Expand Down
19 changes: 19 additions & 0 deletions public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,25 @@ body:not(.metering) #metering-controls {
top: 50px;
}

.comments {
background: rgb(0 0 0 / 85%);
border-radius: 8px;
bottom: 8px;
font-family: sans-serif;
font-size: 16px;
left: 8px;
letter-spacing: 0.5px;
text-transform: capitalize;
padding: 4px 8px;
position: fixed;
z-index: 999;
}

.comments a {
color: white;
text-decoration: none;
}

@keyframes fadeIn {
from {
opacity: 0;
Expand Down

0 comments on commit ffa9142

Please sign in to comment.