Replace hardcoded thumbnail URI and host with configurable ones

This commit is contained in:
Aleksandar Shumakov 2024-05-10 12:23:07 +03:00
parent b07e4451b7
commit 1d35168b5c
3 changed files with 7 additions and 3 deletions

View file

@ -166,6 +166,8 @@ the beginning of the command, before `npm start`:
| `BACKPACK_HOST` | `https://backpack.scratch.mit.edu` | Hostname for backpack requests | | `BACKPACK_HOST` | `https://backpack.scratch.mit.edu` | Hostname for backpack requests |
| `PROJECT_HOST` | `https://projects.scratch.mit.edu` | Hostname for project requests | | `PROJECT_HOST` | `https://projects.scratch.mit.edu` | Hostname for project requests |
| `FALLBACK` | `''` | Pass-through location for old site | | `FALLBACK` | `''` | Pass-through location for old site |
| `THUMBNAIL_URI` | `/intenralapi/project/thumbnail/{}/set/`| URI template for updating project thumbnails, `{}` is replaced by the project ID when invoking a request |
| `THUMBNAIL_HOST` | `''` | Hostname for uploader service|
| `GTM_ID` | `''` | Google Tag Manager ID | | `GTM_ID` | `''` | Google Tag Manager ID |
| `GTM_ENV_AUTH` | `''` | Google Tag Manager env and auth info | | `GTM_ENV_AUTH` | `''` | Google Tag Manager env and auth info |
| `NODE_ENV` | `null` | If not `production`, app acts like development | | `NODE_ENV` | `null` | If not `production`, app acts like development |

View file

@ -689,7 +689,7 @@ module.exports.reportProject = (id, jsonData, token) => (dispatch => {
module.exports.updateProjectThumbnail = (id, blob) => (dispatch => { module.exports.updateProjectThumbnail = (id, blob) => (dispatch => {
dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.FETCHING)); dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.FETCHING));
api({ api({
uri: `/internalapi/project/thumbnail/${id}/set/`, uri: `${process.env.THUMBNAIL_URI.replace('{}', id)}`,
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'image/png' 'Content-Type': 'image/png'
@ -697,7 +697,7 @@ module.exports.updateProjectThumbnail = (id, blob) => (dispatch => {
withCredentials: true, withCredentials: true,
useCsrf: true, useCsrf: true,
body: blob, body: blob,
host: '' // Not handled by the API, use existing infrastructure host: process.env.THUMBNAIL_HOST
}, (err, body, res) => { }, (err, body, res) => {
if (err || res.statusCode !== 200) { if (err || res.statusCode !== 200) {
dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.ERROR)); dispatch(module.exports.setFetchStatus('project-thumbnail', module.exports.Status.ERROR));

View file

@ -248,7 +248,9 @@ module.exports = {
'process.env.CLOUDDATA_HOST': `"${process.env.CLOUDDATA_HOST || 'clouddata.scratch.mit.edu'}"`, 'process.env.CLOUDDATA_HOST': `"${process.env.CLOUDDATA_HOST || 'clouddata.scratch.mit.edu'}"`,
'process.env.PROJECT_HOST': `"${process.env.PROJECT_HOST || 'https://projects.scratch.mit.edu'}"`, 'process.env.PROJECT_HOST': `"${process.env.PROJECT_HOST || 'https://projects.scratch.mit.edu'}"`,
'process.env.STATIC_HOST': `"${process.env.STATIC_HOST || 'https://uploads.scratch.mit.edu'}"`, 'process.env.STATIC_HOST': `"${process.env.STATIC_HOST || 'https://uploads.scratch.mit.edu'}"`,
'process.env.SCRATCH_ENV': `"${process.env.SCRATCH_ENV || 'development'}"` 'process.env.SCRATCH_ENV': `"${process.env.SCRATCH_ENV || 'development'}"`,
'process.env.THUMBNAIL_URI': `"${process.env.THUMBNAIL_URI || '/internalapi/project/thumbnail/{}/set/'}"`,
'process.env.THUMBNAIL_HOST': `"${process.env.THUMBNAIL_HOST || ''}"`
}) })
]) ])
.concat(process.env.ANALYZE_BUNDLE === 'true' ? [ .concat(process.env.ANALYZE_BUNDLE === 'true' ? [