fix(lint): Add ctx shim to routes/apps and routes/arr
- routes/apps/deploy.js: Add ctx shim with APP_TEMPLATES, siteConfig, buildDomain, buildServiceUrl, addServiceToConfig, dns, notification, safeErrorMessage - routes/apps/index.js: Extract additional ctx properties for sub-routes - routes/arr/config.js: Add ctx shim with notification, safeErrorMessage + logError import - routes/arr/index.js: Extract notification, safeErrorMessage for sub-routes Result: Fixed ~30 no-undef errors (deploy.js 0 errors, arr/config.js 0 errors)
This commit is contained in:
5
dashcaddy-api/.eslintignore
Normal file
5
dashcaddy-api/.eslintignore
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
node_modules/
|
||||||
|
coverage/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.min.js
|
||||||
57
dashcaddy-api/.eslintrc.js
Normal file
57
dashcaddy-api/.eslintrc.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
es2021: true,
|
||||||
|
},
|
||||||
|
extends: 'eslint:recommended',
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 'latest',
|
||||||
|
sourceType: 'commonjs',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// Error Prevention
|
||||||
|
'no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
||||||
|
'no-console': 'off', // We use structured logging, but console is okay for debug
|
||||||
|
'no-undef': 'error',
|
||||||
|
'no-unreachable': 'error',
|
||||||
|
'no-constant-condition': ['error', { checkLoops: false }],
|
||||||
|
|
||||||
|
// Code Quality
|
||||||
|
'prefer-const': 'warn',
|
||||||
|
'no-var': 'warn',
|
||||||
|
'eqeqeq': ['warn', 'always', { null: 'ignore' }],
|
||||||
|
'curly': ['warn', 'multi-line'],
|
||||||
|
'no-throw-literal': 'error',
|
||||||
|
|
||||||
|
// Async/Await
|
||||||
|
'require-await': 'warn',
|
||||||
|
'no-async-promise-executor': 'error',
|
||||||
|
'no-await-in-loop': 'off', // Sometimes intentional for sequential operations
|
||||||
|
|
||||||
|
// Style (Prettier handles formatting, these are semantic)
|
||||||
|
'consistent-return': 'off', // Express routes don't always return
|
||||||
|
'no-nested-ternary': 'warn',
|
||||||
|
'max-depth': ['warn', 4],
|
||||||
|
'complexity': ['warn', 20],
|
||||||
|
|
||||||
|
// Prevent common pitfalls
|
||||||
|
'no-eval': 'error',
|
||||||
|
'no-implied-eval': 'error',
|
||||||
|
'no-new-func': 'error',
|
||||||
|
'no-with': 'error',
|
||||||
|
'no-proto': 'error',
|
||||||
|
},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
// Test files can be more lenient
|
||||||
|
files: ['**/__tests__/**/*.js', '**/*.test.js', '**/*.spec.js'],
|
||||||
|
env: {
|
||||||
|
jest: true,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'no-unused-expressions': 'off',
|
||||||
|
'max-depth': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
6
dashcaddy-api/.prettierignore
Normal file
6
dashcaddy-api/.prettierignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
node_modules/
|
||||||
|
coverage/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
package-lock.json
|
||||||
|
*.min.js
|
||||||
10
dashcaddy-api/.prettierrc
Normal file
10
dashcaddy-api/.prettierrc
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "es5",
|
||||||
|
"printWidth": 120,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"endOfLine": "lf"
|
||||||
|
}
|
||||||
4
dashcaddy-api/package-lock.json
generated
4
dashcaddy-api/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "dashcaddy-api",
|
"name": "dashcaddy-api",
|
||||||
"version": "1.1.0",
|
"version": "1.1.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "dashcaddy-api",
|
"name": "dashcaddy-api",
|
||||||
"version": "1.1.0",
|
"version": "1.1.5",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"compression": "^1.8.1",
|
"compression": "^1.8.1",
|
||||||
"cors": "^2.8.6",
|
"cors": "^2.8.6",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const { isValidPort } = require('../../input-validator');
|
|||||||
const { exists } = require('../../fs-helpers');
|
const { exists } = require('../../fs-helpers');
|
||||||
const platformPaths = require('../../platform-paths');
|
const platformPaths = require('../../platform-paths');
|
||||||
const { ValidationError } = require('../errors');
|
const { ValidationError } = require('../errors');
|
||||||
|
const { logError } = require('../../src/utils/logging');
|
||||||
/**
|
/**
|
||||||
* Apps deployment routes factory
|
* Apps deployment routes factory
|
||||||
* @param {Object} deps - Explicit dependencies
|
* @param {Object} deps - Explicit dependencies
|
||||||
@@ -22,8 +23,20 @@ const { ValidationError } = require('../errors');
|
|||||||
* @returns {express.Router}
|
* @returns {express.Router}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function({ docker, caddy, credentialManager, servicesStateManager, portLockManager, asyncHandler, errorResponse, log, helpers }) {
|
module.exports = function({ docker, caddy, credentialManager, servicesStateManager, portLockManager, asyncHandler, errorResponse, log, helpers, APP_TEMPLATES, siteConfig, buildDomain, buildServiceUrl, addServiceToConfig, dns, notification, safeErrorMessage }) {
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
// Ctx shim for backward compatibility with existing route code
|
||||||
|
const ctx = {
|
||||||
|
APP_TEMPLATES,
|
||||||
|
siteConfig,
|
||||||
|
buildDomain,
|
||||||
|
buildServiceUrl,
|
||||||
|
addServiceToConfig,
|
||||||
|
dns,
|
||||||
|
notification,
|
||||||
|
safeErrorMessage
|
||||||
|
};
|
||||||
|
|
||||||
async function deployDashCAStaticSite(template, userConfig) {
|
async function deployDashCAStaticSite(template, userConfig) {
|
||||||
const destPath = platformPaths.caCertDir;
|
const destPath = platformPaths.caCertDir;
|
||||||
@@ -260,6 +273,9 @@ module.exports = function({ docker, caddy, credentialManager, servicesStateManag
|
|||||||
|
|
||||||
let containerId;
|
let containerId;
|
||||||
let usedExisting = false;
|
let usedExisting = false;
|
||||||
|
|
||||||
|
// Process template variables for manifest (only needed for Docker containers)
|
||||||
|
const processedTemplate = template.isStaticSite ? null : helpers.processTemplateVariables(template, config);
|
||||||
|
|
||||||
if (template.isStaticSite) {
|
if (template.isStaticSite) {
|
||||||
log.info('deploy', 'Deploying static site', { appId });
|
log.info('deploy', 'Deploying static site', { appId });
|
||||||
|
|||||||
@@ -23,7 +23,16 @@ module.exports = function(ctx) {
|
|||||||
portLockManager: ctx.portLockManager,
|
portLockManager: ctx.portLockManager,
|
||||||
asyncHandler: ctx.asyncHandler,
|
asyncHandler: ctx.asyncHandler,
|
||||||
errorResponse: ctx.errorResponse,
|
errorResponse: ctx.errorResponse,
|
||||||
log: ctx.log
|
log: ctx.log,
|
||||||
|
// Additional context properties needed by routes
|
||||||
|
APP_TEMPLATES: ctx.APP_TEMPLATES,
|
||||||
|
siteConfig: ctx.siteConfig,
|
||||||
|
buildDomain: ctx.buildDomain,
|
||||||
|
buildServiceUrl: ctx.buildServiceUrl,
|
||||||
|
addServiceToConfig: ctx.addServiceToConfig,
|
||||||
|
dns: ctx.dns,
|
||||||
|
notification: ctx.notification,
|
||||||
|
safeErrorMessage: ctx.safeErrorMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize helpers with dependencies
|
// Initialize helpers with dependencies
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const express = require('express');
|
|||||||
const { APP_PORTS, ARR_SERVICES } = require('../../constants');
|
const { APP_PORTS, ARR_SERVICES } = require('../../constants');
|
||||||
const { validateURL, validateToken } = require('../../input-validator');
|
const { validateURL, validateToken } = require('../../input-validator');
|
||||||
const { ValidationError, AuthenticationError, NotFoundError } = require('../errors');
|
const { ValidationError, AuthenticationError, NotFoundError } = require('../errors');
|
||||||
|
const { logError } = require('../../src/utils/logging');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arr configuration routes factory
|
* Arr configuration routes factory
|
||||||
@@ -16,8 +17,14 @@ const { ValidationError, AuthenticationError, NotFoundError } = require('../erro
|
|||||||
* @param {Object} deps.helpers - Arr helpers module
|
* @param {Object} deps.helpers - Arr helpers module
|
||||||
* @returns {express.Router}
|
* @returns {express.Router}
|
||||||
*/
|
*/
|
||||||
module.exports = function({ credentialManager, servicesStateManager, docker, fetchT, asyncHandler, errorResponse, log, helpers }) {
|
module.exports = function({ credentialManager, servicesStateManager, docker, fetchT, asyncHandler, errorResponse, log, helpers, notification, safeErrorMessage }) {
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
// Ctx shim for backward compatibility
|
||||||
|
const ctx = {
|
||||||
|
notification,
|
||||||
|
safeErrorMessage
|
||||||
|
};
|
||||||
|
|
||||||
// Auto-configure Overseerr with detected services
|
// Auto-configure Overseerr with detected services
|
||||||
router.post('/arr/configure-overseerr', asyncHandler(async (req, res) => {
|
router.post('/arr/configure-overseerr', asyncHandler(async (req, res) => {
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ module.exports = function(ctx) {
|
|||||||
fetchT: ctx.fetchT,
|
fetchT: ctx.fetchT,
|
||||||
asyncHandler: ctx.asyncHandler,
|
asyncHandler: ctx.asyncHandler,
|
||||||
errorResponse: ctx.errorResponse,
|
errorResponse: ctx.errorResponse,
|
||||||
log: ctx.log
|
log: ctx.log,
|
||||||
|
// Additional context properties needed by arr routes
|
||||||
|
notification: ctx.notification,
|
||||||
|
safeErrorMessage: ctx.safeErrorMessage
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize helpers with dependencies
|
// Initialize helpers with dependencies
|
||||||
|
|||||||
Reference in New Issue
Block a user