SERA integration on Fastly¶
Kindly follow the below examples to setup the routing of bot traffic to SERA.
- Change YOUR_TOKEN to the SERA token shared with you
- Keep the relevant bot user-agent regex condition mentioned below - to control the traffic being sent to SERA
(1) Create a backend in the Fastly service¶
- Clone the currently active version and create a backend for SERA.
- You can use the following example code snippet for creating a SERA backend in your Fastly service.
backend o_s {
.always_use_host_header = true;
.between_bytes_timeout = 5s;
.connect_timeout = 10s;
.dynamic = true;
.first_byte_timeout = 45s;
.host = "sera.n7.io";
.host_header = "sera.n7.io";
.port = "443";
.ssl = true;
.ssl_check_cert = never;
.ssl_sni_hostname = "sera.n7.io";
}
(2) Route Crawler requests to SERA¶
- Use the same draft intercept and route the crawler requests to SERA.
- Please refer to the following VCL snippet to intercept and route the required crawler requests to SERA in vcl_recv subroutine.
- You need to add the following snippet in addition to your previous configuration(if any).
- Note: Do not replace vcl_recv subroutine as it is if you have any existing configuration.
sub vcl_recv {
# only send PAGE requests to SERA
if (req.url !~ "(?i).*\.(jpg|jpeg|png|webp|avif|gif|bmp|ico|svg|js|css|woff|woff2|ttf|eot|otf|mp3|mp4|mov|ogg|webm|wav|exe|json|txt|xml|zip|csv|pdf|php|jsp|ashx|aspx|asmx)(\?.*)*$"
&& !req.http.x-nv-app
&& !req.http.x-nv-sera-bypass) {
# DURING POC PHASE - USE THIS if condition for bot User-Agent check :
if (req.http.User-Agent ~ "(?i)(n7TestUserAgent|PTST|GTmetrix)") {
# ON GOING LIVE ON SERA - USE THIS if condition for bot User-Agent check :
if (req.http.User-Agent ~ "(?i)(googlebot|google\ page\ speed|chrome-lighthouse|google-inspectiontool|PTST|GTmetrix)") {
set req.http.X-NV-Sera-Token = {YOUR_TOKEN};
set req.backend = F_o_s;
return(lookup);
}
}
# existing configuration
}
Testing and Refinement¶
- You can test the Fastly configuration on Fiddle
- Keep refining the logic by adjusting user-agent list, and SERA exclusion-patterns as needed.
- Test thoroughly:
- WPT and GTMetrix will automatically receive the response from SERA due to the routing rule set above.
- Steps to validate page using WPT
- To check the SERA rendered page on browser, you can use some browser extension (like Simple modify headers) to manipulate the browser user-agent. If in testing phase, use these user-agent values: For desktop: For mobile: If SERA is live, you can use these actual bot user-agent values: For desktop: For mobile:
- WPT and GTMetrix will automatically receive the response from SERA due to the routing rule set above.
- On go-live day, set the user-agent condition regex to actual bot user-agent values. Additionally, ensure that your condition is case-insensitive.