Skip to content

Commit

Permalink
fix merge issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfrederiksen committed Feb 20, 2025
1 parent d5f66ec commit 5c19b8e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1358,5 +1358,68 @@ module.exports = (fastify, opt, next) => {
return handleAdRequest(req, reply, type);
});

/**
* GET endpoint to retrieve VAST XML for Pause Ads.
*/
fastify.get("/pause-ad", { schema: schemas["GET/pause-ad"] }, async (req, reply) => {
try {
logger.info(req.query, {
label: req.headers["host"],
});
CloudWatchLog("PAUSE_AD_REQUESTED", req.headers["host"], {});

const params = Object.assign(req.query, {
acceptLang: req.headers["accept-language"] || "Not Found",
host: req.headers["host"],
userAgent: req.headers["user-agent"] || "Not Found",
uip: req.headers["x-forwarded-for"] || req.socket.remoteAddress || "Not Found",
rf: RESPONSE_FORMATS.PAUSE_AD,
width: req.query.width ? parseInt(req.query.width) : undefined,
height: req.query.height ? parseInt(req.query.height) : undefined,
});

const session = new Session(params);
const result = await DBAdapter.AddSessionToStorage(session);
if (!result) {
logger.error("Could not store new session", {
label: params.host,
sessionId: session.sessionId,
});
reply.code(404).send({
message: "Could not store new session",
});
return;
}

const pauseAdVast = session.getPauseAdVast();
if (!pauseAdVast) {
logger.error("Pause Ad VAST not found", {
label: params.host,
sessionId: session.sessionId,
});
reply.code(404).send({
message: "Pause Ad VAST not found",
});
return;
}

logger.info("Returned Pause Ad VAST and created a session", {
label: req.headers["host"],
sessionId: session.sessionId,
});
CloudWatchLog("PAUSE_AD_RETURNED", req.headers["host"], {
session: session.sessionId,
});

reply.header("Content-Type", "application/xml; charset=utf-8");
reply.code(200).send(pauseAdVast);
} catch (exc) {
logger.error(exc, {
label: req.headers["host"],
});
reply.code(500).send({ message: exc.message });
}
});

next();
};

0 comments on commit 5c19b8e

Please sign in to comment.