Simplify startup of the puppeteer service

- Run on port 9090 so we don't conflict with other services
- Route the docker-compose requests to the host network
- Dont require preview bucket information on startup
This commit is contained in:
Jackson Harper
2022-02-11 14:43:47 -08:00
parent c96aead838
commit 42836b6b38
3 changed files with 9 additions and 4 deletions

View File

@ -57,7 +57,7 @@ services:
- SSO_JWT_SECRET=some_sso_secret
- CLIENT_URL=http://localhost:3000
- GATEWAY_URL=http://localhost:8080/api
- PUPPETEER_TASK_HANDLER_URL=http://localhost:9090/
- PUPPETEER_TASK_HANDLER_URL=http://host.docker.internal:9090/
- REMINDER_TASK_HANDLER_URL=/svc/reminders/trigger
depends_on:
migrate:

View File

@ -25,8 +25,8 @@ const { pdfHandler } = require('./pdf-handler');
const { mediumHandler } = require('./medium-handler');
const storage = new Storage();
const previewBucket = storage.bucket(process.env.PREVIEW_IMAGE_BUCKET);
const ALLOWED_ORIGINS = process.env.ALLOWED_ORIGINS.split(',');
const ALLOWED_ORIGINS = process.env.ALLOWED_ORIGINS ? process.env.ALLOWED_ORIGINS.split(',') : [];
const previewBucket = process.env.PREVIEW_IMAGE_BUCKET ? storage.bucket(process.env.PREVIEW_IMAGE_BUCKET) : undefined;
Sentry.GCPFunction.init({
dsn: process.env.SENTRY_DSN,
@ -402,6 +402,11 @@ exports.preview = Sentry.GCPFunction.wrapHttpFunction(async (req, res) => {
},
});
if (!process.env.PREVIEW_IMAGE_BUCKET) {
logger.error(`PREVIEW_IMAGE_BUCKET not set`)
return res.sendStatus(500);
}
const url = getUrl(req);
console.log('preview request url', url);

View File

@ -20,7 +20,7 @@
"@google-cloud/functions-framework": "^1.7.1"
},
"scripts": {
"start": "npx functions-framework --target=puppeteer",
"start": "npx functions-framework --port=9090 --target=puppeteer",
"start_preview": "npx functions-framework --target=preview",
"test": "yarn mocha"
}