Skip to content

Conversation

@code-a-cola
Copy link

We have automated script that run outside of NPM. These scripts use the backend api to add and remove proxies, as well as query for existing proxies.

We have scripts the need to pull specific proxies by domain, rather than proxy_id.

Pulling the entire list of proxies to search for a proxy by domain is extremely slow, especially if a large amount of proxies exist.

This pull request will add an endpoint to the backend API to allow the query of proxies by domain name.

@jc21
Copy link
Member

jc21 commented Nov 3, 2025

For some reason, CI doesn't want to build this PR. Perhaps rebasing it in your fork might help?

@nginxproxymanagerci
Copy link

CI Error:

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
certbot-node: Pulling from nginxproxymanager/nginx-full
Digest: sha256:a3f685a6ec6c4a3781242888fbfa53127abec9321d7ae871486ed2246693cdc4
Status: Image is up to date for nginxproxymanager/nginx-full:certbot-node
docker.io/nginxproxymanager/nginx-full:certbot-node
�[1;34m❯ �[1;36mTesting backend ...�[0m
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
warning lru.min@1.1.2: The engine "bun" appears to be invalid.
warning lru.min@1.1.2: The engine "deno" appears to be invalid.
warning " > @apidevtools/swagger-parser@10.1.1" has unmet peer dependency "openapi-types@>=7".
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 10.42s.
yarn run v1.22.22
$ biome lint .
internal/proxy-host.js:287:56 lint/style/useTemplate  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  i Template literals are preferred over string concatenation.
  
    285 │ 					.query()
    286 │ 					.where('is_deleted', 0)
  > 287 │ 					.andWhere(castJsonIfNeed('domain_names'), 'like', '%' + data.domain + '%')
        │ 					                                                  ^^^^^^^^^^^^^^^^^^^^^^^
    288 │ 					.allowGraph('[owner,access_list.[clients,items],certificate]')
    289 │ 					.modify(function(queryBuilder) {
  
  i Unsafe fix: Use a template literal.
  
    285 285 │   					.query()
    286 286 │   					.where('is_deleted', 0)
    287     │ - → → → → → .andWhere(castJsonIfNeed('domain_names'),·'like',·'%'·+·data.domain·+·'%')
        287 │ + → → → → → .andWhere(castJsonIfNeed('domain_names'),·'like',·`%${data.domain}%`)
    288 288 │   					.allowGraph('[owner,access_list.[clients,items],certificate]')
    289 289 │   					.modify(function(queryBuilder) {
  

internal/proxy-host.js:301:29 lint/style/useTemplate  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  i Template literals are preferred over string concatenation.
  
    300 │ 				if (typeof data.expand !== 'undefined' && data.expand !== null) {
  > 301 │ 					query.withGraphFetched('[' + data.expand.join(', ') + ']');
        │ 					                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    302 │ 				}
    303 │ 
  
  i Unsafe fix: Use a template literal.
  
    299 299 │   
    300 300 │   				if (typeof data.expand !== 'undefined' && data.expand !== null) {
    301     │ - → → → → → query.withGraphFetched('['·+·data.expand.join(',·')·+·']');
        301 │ + → → → → → query.withGraphFetched(`[${data.expand.join(',·')}]`);
    302 302 │   				}
    303 303 │   
  

internal/proxy-host.js:289:14 lint/complexity/useArrowFunction  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! This function expression can be turned into an arrow function.
  
    287 │ 					.andWhere(castJsonIfNeed('domain_names'), 'like', '%' + data.domain + '%')
    288 │ 					.allowGraph('[owner,access_list.[clients,items],certificate]')
  > 289 │ 					.modify(function(queryBuilder) {
        │ 					        ^^^^^^^^^^^^^^^^^^^^^^^^
  > 290 │ 						if (data.expand) {
  > 291 │ 							queryBuilder.withGraphFetched(`[${data.expand.join(', ')}]`);
  > 292 │ 						}
  > 293 │ 					})
        │ 					^
    294 │ 					.first();
    295 │ 
  
  i Function expressions that don't use this can be turned into arrow functions.
  
  i Safe fix: Use an arrow function instead.
  
    287 287 │   					.andWhere(castJsonIfNeed('domain_names'), 'like', '%' + data.domain + '%')
    288 288 │   					.allowGraph('[owner,access_list.[clients,items],certificate]')
    289     │ - → → → → → .modify(function(queryBuilder)·{
        289 │ + → → → → → .modify((queryBuilder)·=>·{
    290 290 │   						if (data.expand) {
    291 291 │   							queryBuilder.withGraphFetched(`[${data.expand.join(', ')}]`);
  

internal/proxy-host.js:284:5 lint/style/useConst  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ! This let declares a variable that is only assigned once.
  
    282 │ 		return access.can('proxy_hosts:get', data.domain)
    283 │ 			.then((access_data) => {
  > 284 │ 				let query = proxyHostModel
        │ 				^^^
    285 │ 					.query()
    286 │ 					.where('is_deleted', 0)
  
  i 'query' is never reassigned.
  
    282 │ 		return access.can('proxy_hosts:get', data.domain)
    283 │ 			.then((access_data) => {
  > 284 │ 				let query = proxyHostModel
        │ 				    ^^^^^
    285 │ 					.query()
    286 │ 					.where('is_deleted', 0)
  
  i Safe fix: Use const instead.
  
    282 282 │   		return access.can('proxy_hosts:get', data.domain)
    283 283 │   			.then((access_data) => {
    284     │ - → → → → let·query·=·proxyHostModel
        284 │ + → → → → const·query·=·proxyHostModel
    285 285 │   					.query()
    286 286 │   					.where('is_deleted', 0)
  

routes/nginx/proxy_hosts.js:162:12 lint/correctness/noUnusedFunctionParameters  FIXABLE  ━━━━━━━━━━━

  ! This parameter is unused.
  
    160 │ router
    161 │ 	.route('/domain/:domain')
  > 162 │ 	.options((req, res) => {
        │ 	          ^^^
    163 │ 		res.sendStatus(204);
    164 │ 	})
  
  i Unused parameters might be the result of an incomplete refactoring.
  
  i Unsafe fix: If this is intentional, prepend req with an underscore.
  
    160 160 │   router
    161 161 │   	.route('/domain/:domain')
    162     │ - → .options((req,·res)·=>·{
        162 │ + → .options((_req,·res)·=>·{
    163 163 │   		res.sendStatus(204);
    164 164 │   	})
  

internal/proxy-host.js:279:4 lint/style/noParameterAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  × Assigning a function parameter is confusing.
  
    277 │ 	getByDomain: (access, data) => {
    278 │ 		if (typeof data === 'undefined') {
  > 279 │ 			data = {};
        │ 			^^^^
    280 │ 		}
    281 │ 
  
  i The parameter is declared here:
  
    275 │ 	 * @return {Promise}
    276 │ 	 */
  > 277 │ 	getByDomain: (access, data) => {
        │ 	                      ^^^^
    278 │ 		if (typeof data === 'undefined') {
    279 │ 			data = {};
  
  i Developers usually expect function parameters to be readonly. To align with this expectation, use a local variable instead.
  

internal/proxy-host.js:310:5 lint/style/noParameterAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  × Assigning a function parameter is confusing.
  
    308 │ 					throw new error.ItemNotFoundError(data.id);
    309 │ 				}
  > 310 │ 				row = internalHost.cleanRowCertificateMeta(row);
        │ 				^^^
    311 │ 				// Custom omissions
    312 │ 				if (typeof data.omit !== 'undefined' && data.omit !== null) {
  
  i The parameter is declared here:
  
    304 │ 				return query.then(utils.omitRow(omissions()));
    305 │ 			})
  > 306 │ 			.then((row) => {
        │ 			       ^^^
    307 │ 				if (!row || !row.id) {
    308 │ 					throw new error.ItemNotFoundError(data.id);
  
  i Developers usually expect function parameters to be readonly. To align with this expectation, use a local variable instead.
  

internal/proxy-host.js:313:6 lint/style/noParameterAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  × Assigning a function parameter is confusing.
  
    311 │ 				// Custom omissions
    312 │ 				if (typeof data.omit !== 'undefined' && data.omit !== null) {
  > 313 │ 					row = _.omit(row, data.omit);
        │ 					^^^
    314 │ 				}
    315 │ 				return row;
  
  i The parameter is declared here:
  
    304 │ 				return query.then(utils.omitRow(omissions()));
    305 │ 			})
  > 306 │ 			.then((row) => {
        │ 			       ^^^
    307 │ 				if (!row || !row.id) {
    308 │ 					throw new error.ItemNotFoundError(data.id);
  
  i Developers usually expect function parameters to be readonly. To align with this expectation, use a local variable instead.
  

Checked 83 files in 57ms. No fixes applied.
Found 3 errors.
Found 3 warnings.
Found 2 infos.
lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  × Some errors were emitted while running checks.
  

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants