nginx-proxy-manager icon indicating copy to clipboard operation
nginx-proxy-manager copied to clipboard

query by domain endpoint

Open code-a-cola opened this issue 7 months ago • 2 comments

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.

code-a-cola avatar Apr 28 '25 15:04 code-a-cola

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

jc21 avatar Nov 03 '25 21:11 jc21

CI Error:

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
certbot-node: Pulling from nginxproxymanager/nginx-full
Digest: sha256:34a4867931ac3ef308cd244202fc774edc306d201c8374839d6dee7fbe1d6b57
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 [email protected]: The engine "bun" appears to be invalid.
warning [email protected]: The engine "deno" appears to be invalid.
[3/4] Linking dependencies...
warning " > @apidevtools/[email protected]" has unmet peer dependency "openapi-types@>=7".
[4/4] Building fresh packages...
Done in 7.35s.
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: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:207:12 lint/correctness/noUnusedFunctionParameters  FIXABLE  ━━━━━━━━━━━

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

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 86 files in 27ms. No fixes applied.
Found 3 errors.
Found 3 warnings.
Found 1 info.
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.