Skip to content

Commit

Permalink
Fix CSP error and build log crashes in dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Jan 20, 2022
1 parent 926b118 commit 8bb13c6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/api/status/env.local
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PLANET_PORT=1111
PATH_PREFIX=/v1/status
API_HOST=localhost
WEB_URL=localhost
POSTS_URL=http://localhost/v1/posts
MOCK_REDIS=1
4 changes: 2 additions & 2 deletions src/api/status/public/js/build-log/build-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ function renderBuildInfo({ isCurrent, githubData, startedDate, stoppedDate, code
}

export default function buildHeader(build) {
if (build && !build.stoppedDate) {
if (!build) {
const icon = document.createElement('i');
icon.className = 'fas fa-server px-2';
buildHeaderTitle.innerHTML = '';
buildHeaderTitle.append(icon);
buildHeaderTitle.innerHTML += 'There is no current or previous build at the moment.';
buildHeaderTitle.innerHTML += 'Unable to get build info at the moment. Please try again later.';
buildHeaderInfo.innerHTML = '';
return;
}
Expand Down
10 changes: 3 additions & 7 deletions src/api/status/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const getFeedCount = require('./js/feed-stats');
const getPostsCount = require('./js/posts-stats');
const getJobCount = require('./js/queue-stats');

const host = process.env.API_HOST || 'localhost';
// We need to be able to talk to the autodeployment server
const autodeploymentHost = process.env.WEB_URL || 'localhost';

const satelliteOptions = {
helmet: {
Expand All @@ -23,12 +24,7 @@ const satelliteOptions = {
'fonts.googleapis.com',
'cdn.jsdelivr.net',
],
connectSrc: [
"'self'",
'*.fontawesome.com',
`${host.replace(/(^\w+:|^)\/\//, '')}/deploy`,
'*.github.com',
],
connectSrc: ["'self'", '*.fontawesome.com', autodeploymentHost, '*.github.com'],
fontSrc: ["'self'", 'data:', 'https:', '*.fontawesome.com'],
imgSrc: ["'self'", 'data:', 'https:'],
},
Expand Down
9 changes: 5 additions & 4 deletions tools/autodeployment/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,17 @@ module.exports.buildLogHandler = function (buildName) {
return;
}

const { out, cache } = build;

res.writeHead(200, { 'Content-Type': 'text/plain' });

// Send the cached build log, which is either everything, or everything so far
const buildLog = build.cache.getContents();
if (buildLog) {
res.write(buildLog);
const cached = cache.getContents();
if (cached) {
res.write(cached);
}

// If we don't have a build happening, we're done
const { out } = build;
if (!out) {
res.end();
return;
Expand Down

0 comments on commit 8bb13c6

Please sign in to comment.