[web] Remove the nocdn fallback (#29311)

* Remove the nocdn fallback

Co-authored-by: Tim Down <tim.down@overleaf.com>

* Remove comment about nocdn query string in ExpressLocals.mjs

Co-authored-by: Tim Down <tim.down@overleaf.com>

* Remove `Frontend` global

---------

Co-authored-by: Tim Down <tim.down@overleaf.com>
GitOrigin-RevId: 74160ed4cf8ba17f8bd9b6793c8baa80883d3361
This commit is contained in:
Antoine Clausse
2025-11-11 14:06:45 +01:00
committed by Copybot
parent 92a14715ec
commit f028f21e3c
4 changed files with 1 additions and 139 deletions
@@ -1,5 +1,4 @@
import logger from '@overleaf/logger'
import Metrics from '@overleaf/metrics'
import Settings from '@overleaf/settings'
import _ from 'lodash'
import { URL } from 'node:url'
@@ -127,27 +126,9 @@ export default async function (webRouter, privateApiRouter, publicApiRouter) {
const cdnAvailable =
Settings.cdn && Settings.cdn.web && !!Settings.cdn.web.host
const cdnBlocked =
req.query.nocdn === 'true' || req.session.cdnBlocked || false
const userId = SessionManager.getLoggedInUserId(req.session)
if (cdnBlocked && req.session.cdnBlocked == null) {
logger.debug(
{ userId, ip: req != null ? req.ip : undefined },
'cdnBlocked for user, not using it and turning it off for future requets'
)
Metrics.inc('no_cdn', 1, {
path: userId ? 'logged-in' : 'pre-login',
method: 'true',
})
req.session.cdnBlocked = true
}
Metrics.inc('cdn_blocked', 1, {
path: userId ? 'logged-in' : 'pre-login',
method: String(cdnBlocked),
})
const host = req.headers && req.headers.host
const isSmoke = host.slice(0, 5).toLowerCase() === 'smoke'
if (cdnAvailable && !isSmoke && !cdnBlocked) {
if (cdnAvailable && !isSmoke) {
staticFilesBase = Settings.cdn.web.host
} else {
staticFilesBase = ''
@@ -232,7 +213,6 @@ export default async function (webRouter, privateApiRouter, publicApiRouter) {
}
// Don't include the query string parameters, otherwise Google
// treats ?nocdn=true as the canonical version
try {
const parsedOriginalUrl = new URL(req.originalUrl, Settings.siteUrl)
res.locals.currentUrl = parsedOriginalUrl.pathname
-19
View File
@@ -126,22 +126,3 @@ html(
+foot-scripts
include _customer_io
script(type='text/javascript' nonce=scriptNonce).
window.addEventListener('DOMContentLoaded', function () {
var bots = ['Bytespider', 'TikTokSpider', 'bingbot', 'Baiduspider', 'Amazonbot', 'Googlebot']
//- Look for bundle
var cdnBlocked = typeof Frontend === 'undefined'
//- Prevent loops
var noCdnAlreadyInUrl = window.location.href.indexOf('nocdn=true') != -1
if (
cdnBlocked &&
!noCdnAlreadyInUrl &&
!bots.some(function (bot) {
return navigator.userAgent.indexOf(bot) !== -1
})
) {
//- Set query param, server will not set CDN url
window.location.search += '&nocdn=true'
}
})
@@ -1,97 +0,0 @@
import { expect } from 'chai'
import UserHelper from './helpers/User.mjs'
import MetricsHelper from './helpers/metrics.mjs'
const User = UserHelper.promises
const getMetric = MetricsHelper.promises.getMetric
describe('CDNMigration', function () {
let anon, user
beforeEach(async function () {
anon = new User()
user = new User()
await user.login()
})
let noCdnPreLogin, noCdnLoggedIn
let cdnBlockedTruePreLogin, cdnBlockedTrueLoggedIn
let cdnBlockedFalsePreLogin, cdnBlockedFalseLoggedIn
async function getNoCdn(path) {
return await getMetric(
line => line.includes('no_cdn') && line.includes(path)
)
}
async function getCdnBlocked(path, method) {
return await getMetric(
line =>
line.includes('cdn_blocked') &&
line.includes(`path="${path}"`) &&
line.includes(`method="${method}"`)
)
}
beforeEach(async function () {
noCdnPreLogin = await getNoCdn('pre-login')
noCdnLoggedIn = await getNoCdn('logged-in')
cdnBlockedTruePreLogin = await getCdnBlocked('pre-login', 'true')
cdnBlockedTrueLoggedIn = await getCdnBlocked('logged-in', 'true')
cdnBlockedFalsePreLogin = await getCdnBlocked('pre-login', 'false')
cdnBlockedFalseLoggedIn = await getCdnBlocked('logged-in', 'false')
})
describe('pre-login', function () {
it('should collect no_cdn', async function () {
await anon.doRequest('GET', '/login?nocdn=true')
expect(await getNoCdn('pre-login')).to.equal(noCdnPreLogin + 1)
})
it('should collect cdn_blocked', async function () {
await anon.doRequest('GET', '/login')
await anon.doRequest('GET', '/login')
await anon.doRequest('GET', '/login')
expect(await getCdnBlocked('pre-login', 'false')).to.equal(
cdnBlockedFalsePreLogin + 3
)
expect(await getCdnBlocked('pre-login', 'true')).to.equal(
cdnBlockedTruePreLogin
)
})
it('should collect cdn_blocked after nocdn', async function () {
await anon.doRequest('GET', '/login?nocdn=true')
await anon.doRequest('GET', '/login')
expect(await getCdnBlocked('pre-login', 'false')).to.equal(
cdnBlockedFalsePreLogin
)
expect(await getCdnBlocked('pre-login', 'true')).to.equal(
cdnBlockedTruePreLogin + 2
)
})
})
describe('logged-in', function () {
it('should collect no_cdn', async function () {
await user.doRequest('GET', '/project?nocdn=true')
expect(await getNoCdn('logged-in')).to.equal(noCdnLoggedIn + 1)
})
it('should collect cdn_blocked=false before nocdn', async function () {
await user.doRequest('GET', '/project')
await user.doRequest('GET', '/project')
await user.doRequest('GET', '/project')
expect(await getCdnBlocked('logged-in', 'false')).to.equal(
cdnBlockedFalseLoggedIn + 3
)
expect(await getCdnBlocked('logged-in', 'true')).to.equal(
cdnBlockedTrueLoggedIn
)
})
it('should collect cdn_blocked=true after nocdn=true', async function () {
await user.doRequest('GET', '/project?nocdn=true')
await user.doRequest('GET', '/project')
expect(await getCdnBlocked('logged-in', 'false')).to.equal(
cdnBlockedFalseLoggedIn
)
expect(await getCdnBlocked('logged-in', 'true')).to.equal(
cdnBlockedTrueLoggedIn + 2
)
})
})
})
-2
View File
@@ -102,8 +102,6 @@ module.exports = {
// Output as UMD bundle (allows main JS to import with CJS, AMD or global
// style code bundles
libraryTarget: 'umd',
// Name the exported variable from output bundle
library: ['Frontend', '[name]'],
},
optimization: {