Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna2134 committed Dec 12, 2023
1 parent 9c4409c commit 9d7a671
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 2 additions & 4 deletions manifests/api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ spec:
ports:
- containerPort: 3000
env:
- name: BROWSER_ADDRESS
value: "chromium-svc"
- name: BROWSER_PORT
value: "9222"
- name: KUBERNETES_MODE
value: "true"
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { promises as dns, ADDRCONFIG } from "dns";

const app = express();

const kubernetesMode = process.env.KUBERNETES === "true";
const kubernetesMode = process.env.KUBERNETES_MODE === "true";

app.get("/", async (req, res) => {
try {
Expand All @@ -14,19 +14,22 @@ app.get("/", async (req, res) => {
});
}
let addr = "";
let port = "";
if (kubernetesMode) {
addr = process.env.CHROMIUM_SVC_SERVICE_HOST as string;
port = process.env.CHROMIUM_SVC_SERVICE_PORT as string;
} else {
const { address } = await dns.lookup(process.env.BROWSER_ADDRESS as string, {
family: 4,
hints: ADDRCONFIG,
});
addr = address;
port = process.env.BROWSER_PORT as string;
};
if (!addr) {
return res.status(500).send("Address not found");
}
const browser = await puppeteer.connect({ browserURL: `http://${addr}:${process.env.BROWSER_PORT}` });
const browser = await puppeteer.connect({ browserURL: `http://${addr}:${port}` });
const page = await browser.newPage();
await page.setViewport({
height: Number(req.query.height ?? "960"),
Expand Down

0 comments on commit 9d7a671

Please sign in to comment.