Skip to content

Commit

Permalink
chore(api/npm/service-worker.js): clean up lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Apr 23, 2024
1 parent e586fa4 commit ae34580
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion api/npm/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import util from '../util.js'

const DEBUG_LABEL = ' <span\\sstyle="color:\\s#fb8817;"><b>npm</b></span>'

/**
* @ignore
* @param {Request}
* @param {object} env
* @param {import('../service-worker/context.js').Context} ctx
* @return {Promise<Response|null>}
*/
export async function onRequest (request, env, ctx) {
// eslint-disable-next-line
void env, ctx;
if (process.env.SOCKET_RUNTIME_NPM_DEBUG) {
console.debug(request.url)
}
Expand All @@ -25,6 +34,7 @@ export async function onRequest (request, env, ctx) {
let origins = []

if (referer && !referer.startsWith('blob:')) {
// @ts-ignore
if (URL.canParse(referer, origin)) {
const refererURL = new URL(referer, origin)
if (refererURL.href.endsWith('/')) {
Expand All @@ -42,8 +52,10 @@ export async function onRequest (request, env, ctx) {
origins.push(new URL(value, `socket://${url.host}${url.pathname}`).href.replace(/\/$/, ''))
} else if (value.startsWith('/')) {
origins.push(new URL(value, origin).href)
// @ts-ignore
} else if (URL.canParse(value)) {
origins.push(value)
// @ts-ignore
} else if (URL.canParse(`socket://${value}`)) {
origins.push(`socket://${value}`)
}
Expand All @@ -55,7 +67,7 @@ export async function onRequest (request, env, ctx) {
if (process.env.SOCKET_RUNTIME_NPM_DEBUG) {
console.debug('resolving: npm:%s (%o)', specifier, origins)
}

while (origins.length && resolved === null) {
const potentialOrigins = []
const origin = origins.shift()
Expand Down

0 comments on commit ae34580

Please sign in to comment.