diff --git a/services/web/app/src/infrastructure/ExpressLocals.mjs b/services/web/app/src/infrastructure/ExpressLocals.mjs index a509067c22..05281be6e2 100644 --- a/services/web/app/src/infrastructure/ExpressLocals.mjs +++ b/services/web/app/src/infrastructure/ExpressLocals.mjs @@ -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 diff --git a/services/web/app/views/layout-base.pug b/services/web/app/views/layout-base.pug index f5659f3ddc..fd35ca8d02 100644 --- a/services/web/app/views/layout-base.pug +++ b/services/web/app/views/layout-base.pug @@ -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' - } - }) diff --git a/services/web/test/acceptance/src/CDNMigrationTests.mjs b/services/web/test/acceptance/src/CDNMigrationTests.mjs deleted file mode 100644 index b837b16bf6..0000000000 --- a/services/web/test/acceptance/src/CDNMigrationTests.mjs +++ /dev/null @@ -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 - ) - }) - }) -}) diff --git a/services/web/webpack.config.js b/services/web/webpack.config.js index a0f5229b6d..3b795a6122 100644 --- a/services/web/webpack.config.js +++ b/services/web/webpack.config.js @@ -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: {