mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-07-05 12:36:13 -07:00
chore: add typecheck and linting for backend
This commit is contained in:
parent
70c580474c
commit
bdf406f99f
10 changed files with 124 additions and 11 deletions
63
backend/.eslintrc.json
Normal file
63
backend/.eslintrc.json
Normal file
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"plugins": [
|
||||
"@typescript-eslint",
|
||||
"unicorn",
|
||||
"jsdoc",
|
||||
"import",
|
||||
"promise",
|
||||
"sonarjs"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:n/recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:unicorn/recommended",
|
||||
"plugin:jsdoc/recommended",
|
||||
"plugin:import/recommended",
|
||||
"plugin:promise/recommended",
|
||||
"plugin:sonarjs/recommended",
|
||||
"plugin:security/recommended"
|
||||
],
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json",
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"argsIgnorePattern": "^_",
|
||||
"varsIgnorePattern": "^_",
|
||||
"ignoreRestSiblings": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-misused-promises": [
|
||||
"error",
|
||||
{
|
||||
"checksVoidReturn": false
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-var-requires": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"jsdoc/require-jsdoc": ["warn", { "publicOnly": true }],
|
||||
"jsdoc/require-description": "off",
|
||||
"import/no-unresolved": "off",
|
||||
"unicorn/no-empty-file": "off",
|
||||
"unicorn/consistent-function-scoping": [
|
||||
"error",
|
||||
{
|
||||
"checkArrowFunctions": false
|
||||
}
|
||||
],
|
||||
"unicorn/prefer-module": "off",
|
||||
"unicorn/prevent-abbreviations": "off",
|
||||
"unicorn/catch-error-name": "off",
|
||||
"unicorn/prefer-ternary": "off",
|
||||
"unicorn/prefer-event-target": "off",
|
||||
"security/detect-object-injection": "off",
|
||||
"security/detect-non-literal-fs-filename": "off"
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ if (
|
|||
process.env.NODE_ENV === "production" &&
|
||||
process.env.ZU_SECURE_HEADERS !== "false"
|
||||
) {
|
||||
// @ts-ignore
|
||||
app.use(helmet());
|
||||
}
|
||||
|
||||
|
|
1
backend/global.d.ts
vendored
Normal file
1
backend/global.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
declare module "axios";
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"exclude": ["node_modules", "**/node_modules/*"],
|
||||
"typeAcquisition": {
|
||||
"exclude": ["dotenv"]
|
||||
}
|
||||
}
|
|
@ -2,20 +2,36 @@
|
|||
"name": "backend",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node ./bin/www"
|
||||
"start": "node ./bin/www",
|
||||
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
|
||||
"typecheck": "tsc --pretty --noEmit -p tsconfig.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"compression": "^1.7.4",
|
||||
"debug": "~4.3.4",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "~4.18.1",
|
||||
"debug": "^4.3.4",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"express-bearer-token": "^2.4.0",
|
||||
"helmet": "^5.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
"lowdb": "^1.0.0",
|
||||
"morgan": "~1.10.0",
|
||||
"morgan": "^1.10.0",
|
||||
"node-cron": "^3.0.2",
|
||||
"pbkdf2-wrapper": "^1.3.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.18",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||
"@typescript-eslint/parser": "^6.7.4",
|
||||
"eslint": "^8.50.0",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"eslint-plugin-jsdoc": "^46.8.2",
|
||||
"eslint-plugin-n": "^16.1.0",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"eslint-plugin-security": "^1.7.1",
|
||||
"eslint-plugin-sonarjs": "^0.21.0",
|
||||
"eslint-plugin-unicorn": "^48.0.1",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ const api = require("../utils/controller-api");
|
|||
|
||||
// get all members
|
||||
router.get("/", auth.isAuthorized, async function (req, res) {
|
||||
// @ts-ignore
|
||||
const nwid = req.params.nwid;
|
||||
api
|
||||
.get("controller/network/" + nwid + "/member")
|
||||
|
@ -23,6 +24,7 @@ router.get("/", auth.isAuthorized, async function (req, res) {
|
|||
|
||||
// get member
|
||||
router.get("/:mid", auth.isAuthorized, async function (req, res) {
|
||||
// @ts-ignore
|
||||
const nwid = req.params.nwid;
|
||||
const mid = req.params.mid;
|
||||
const data = await member.getMembersData(nwid, [mid]);
|
||||
|
@ -35,6 +37,7 @@ router.get("/:mid", auth.isAuthorized, async function (req, res) {
|
|||
|
||||
// update member
|
||||
router.post("/:mid", auth.isAuthorized, async function (req, res) {
|
||||
// @ts-ignore
|
||||
const nwid = req.params.nwid;
|
||||
const mid = req.params.mid;
|
||||
member.updateMemberAdditionalData(nwid, mid, req.body);
|
||||
|
@ -56,6 +59,7 @@ router.post("/:mid", auth.isAuthorized, async function (req, res) {
|
|||
|
||||
// delete member
|
||||
router.delete("/:mid", auth.isAuthorized, async function (req, res) {
|
||||
// @ts-ignore
|
||||
const nwid = req.params.nwid;
|
||||
const mid = req.params.mid;
|
||||
member.deleteMemberAdditionalData(nwid, mid);
|
||||
|
|
|
@ -71,6 +71,7 @@ async function getMemberAdditionalData(data) {
|
|||
networkId: data.nwid,
|
||||
nodeId: data.id,
|
||||
controllerId: ZT_ADDRESS,
|
||||
// @ts-ignore
|
||||
lastOnline: lastOnline,
|
||||
...additionalData,
|
||||
...peerData,
|
||||
|
|
18
backend/tsconfig.json
Normal file
18
backend/tsconfig.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"baseUrl": ".",
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"target": "ESNext",
|
||||
"lib": ["ESNext", "dom"],
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["."]
|
||||
}
|
|
@ -6,6 +6,7 @@ module.exports = async function () {
|
|||
return res.data.address;
|
||||
} catch (err) {
|
||||
console.error(
|
||||
// @ts-ignore
|
||||
"Couldn't connect to the controller on " + err.config.baseURL
|
||||
);
|
||||
}
|
||||
|
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"target": "ESNext",
|
||||
"lib": ["ESNext", "dom"],
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["backend", "frontend"]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue