mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-23 17:24:04 +02:00
Merge branch 'louislam:master' into master
This commit is contained in:
commit
46a18a60ce
8 changed files with 6267 additions and 38 deletions
17
.eslintrc.js
17
.eslintrc.js
|
@ -91,6 +91,23 @@ module.exports = {
|
||||||
"rules": {
|
"rules": {
|
||||||
"comma-dangle": ["error", "always-multiline"],
|
"comma-dangle": ["error", "always-multiline"],
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Override for jest puppeteer
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"**/*.spec.js",
|
||||||
|
"**/*.spec.jsx"
|
||||||
|
],
|
||||||
|
env: {
|
||||||
|
jest: true,
|
||||||
|
},
|
||||||
|
globals: {
|
||||||
|
page: true,
|
||||||
|
browser: true,
|
||||||
|
context: true,
|
||||||
|
jestPuppeteer: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,3 +11,4 @@ dist-ssr
|
||||||
|
|
||||||
/private
|
/private
|
||||||
/out
|
/out
|
||||||
|
/tmp
|
||||||
|
|
|
@ -4,7 +4,26 @@ First of all, thank you everyone who made pull requests for Uptime Kuma, I never
|
||||||
|
|
||||||
The project was created with vite.js (vue3). Then I created a sub-directory called "server" for server part. Both frontend and backend share the same package.json.
|
The project was created with vite.js (vue3). Then I created a sub-directory called "server" for server part. Both frontend and backend share the same package.json.
|
||||||
|
|
||||||
The frontend code build into "dist" directory. The server uses "dist" as root. This is how production is working.
|
The frontend code build into "dist" directory. The server (express.js) exposes the "dist" directory as root of the endpoint. This is how production is working.
|
||||||
|
|
||||||
|
# Key Technical Skills
|
||||||
|
|
||||||
|
- Node.js (You should know what are promise, async/await and arrow function etc.)
|
||||||
|
- Socket.io
|
||||||
|
- SCSS
|
||||||
|
- Vue.js
|
||||||
|
- Bootstrap
|
||||||
|
- SQLite
|
||||||
|
|
||||||
|
# Directories
|
||||||
|
|
||||||
|
- data (App data)
|
||||||
|
- dist (Frontend build)
|
||||||
|
- extra (Extra useful scripts)
|
||||||
|
- public (Frontend resources for dev only)
|
||||||
|
- server (Server source code)
|
||||||
|
- src (Frontend source code)
|
||||||
|
- test (unit test)
|
||||||
|
|
||||||
# Can I create a pull request for Uptime Kuma?
|
# Can I create a pull request for Uptime Kuma?
|
||||||
|
|
||||||
|
@ -43,15 +62,14 @@ It changed my current workflow and require further studies.
|
||||||
|
|
||||||
I personally do not like something need to learn so much and need to config so much before you can finally start the app.
|
I personally do not like something need to learn so much and need to config so much before you can finally start the app.
|
||||||
|
|
||||||
For example, recently, because I am not a python expert, I spent a 2 hours to resolve all problems in order to install and use the Apprise cli. Apprise requires so many hidden requirements, I have to figure out myself how to solve the problems by Google search for my OS. That is painful. I do not want Uptime Kuma to be like this way, so:
|
|
||||||
|
|
||||||
- Easy to install for non-Docker users, no native build dependency is needed (at least for x86_64), no extra config, no extra effort to get it run
|
- Easy to install for non-Docker users, no native build dependency is needed (at least for x86_64), no extra config, no extra effort to get it run
|
||||||
- Single container for Docker users, no very complex docker-composer file. Just map the volume and expose the port, then good to go
|
- Single container for Docker users, no very complex docker-composer file. Just map the volume and expose the port, then good to go
|
||||||
- All settings in frontend.
|
- Settings should be configurable in the frontend. Env var is not encouraged.
|
||||||
- Easy to use
|
- Easy to use
|
||||||
|
|
||||||
# Coding Styles
|
# Coding Styles
|
||||||
|
|
||||||
|
- 4 spaces indentation
|
||||||
- Follow `.editorconfig`
|
- Follow `.editorconfig`
|
||||||
- Follow ESLint
|
- Follow ESLint
|
||||||
|
|
||||||
|
@ -65,22 +83,16 @@ For example, recently, because I am not a python expert, I spent a 2 hours to re
|
||||||
|
|
||||||
- Node.js >= 14
|
- Node.js >= 14
|
||||||
- Git
|
- Git
|
||||||
- IDE that supports EditorConfig and ESLint (I am using Intellji Idea)
|
- IDE that supports ESLint and EditorConfig (I am using Intellji Idea)
|
||||||
- A SQLite tool (I am using SQLite Expert Personal)
|
- A SQLite tool (SQLite Expert Personal is suggested)
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install --dev
|
npm ci
|
||||||
```
|
```
|
||||||
|
|
||||||
For npm@7, you need --legacy-peer-deps
|
# How to start the Backend Dev Server
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install --legacy-peer-deps --dev
|
|
||||||
```
|
|
||||||
|
|
||||||
# Backend Dev
|
|
||||||
|
|
||||||
(2021-09-23 Update)
|
(2021-09-23 Update)
|
||||||
|
|
||||||
|
@ -96,28 +108,24 @@ It is mainly a socket.io app + express.js.
|
||||||
|
|
||||||
express.js is just used for serving the frontend built files (index.html, .js and .css etc.)
|
express.js is just used for serving the frontend built files (index.html, .js and .css etc.)
|
||||||
|
|
||||||
# Frontend Dev
|
- model/ (Object model, auto mapping to the database table name)
|
||||||
|
- modules/ (Modified 3rd-party modules)
|
||||||
|
- notification-providers/ (indivdual notification logic)
|
||||||
|
- routers/ (Express Routers)
|
||||||
|
- scoket-handler (Socket.io Handlers)
|
||||||
|
- server.js (Server main logic)
|
||||||
|
|
||||||
Start frontend dev server. Hot-reload enabled in this way. It binds to `0.0.0.0:3000` by default.
|
# How to start the Frontend Dev Server
|
||||||
|
|
||||||
```bash
|
1. Set the env var `NODE_ENV` to "development".
|
||||||
npm run dev
|
1. Start the frontend dev server by the following command.
|
||||||
```
|
```bash
|
||||||
|
npm run dev
|
||||||
PS: You can ignore those scss warnings, those warnings are from Bootstrap that I cannot fix.
|
```
|
||||||
|
It binds to `0.0.0.0:3000` by default.
|
||||||
|
|
||||||
You can use Vue.js devtools Chrome extension for debugging.
|
You can use Vue.js devtools Chrome extension for debugging.
|
||||||
|
|
||||||
After the frontend server started. It cannot connect to the websocket server even you have started the server. You need to tell the frontend that is a dev env by running this in DevTool console and refresh:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
localStorage.dev = "dev";
|
|
||||||
```
|
|
||||||
|
|
||||||
So that the frontend will try to connect websocket server in 3001.
|
|
||||||
|
|
||||||
Alternately, you can specific `NODE_ENV` to "development".
|
|
||||||
|
|
||||||
## Build the frontend
|
## Build the frontend
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -134,10 +142,11 @@ As you can see, most data in frontend is stored in root level, even though you c
|
||||||
|
|
||||||
The data and socket logic are in `src/mixins/socket.js`.
|
The data and socket logic are in `src/mixins/socket.js`.
|
||||||
|
|
||||||
|
|
||||||
# Database Migration
|
# Database Migration
|
||||||
|
|
||||||
1. Create `patch{num}.sql` in `./db/`
|
1. Create `patch-{name}.sql` in `./db/`
|
||||||
2. Update `latestVersion` in `./server/database.js`
|
2. Add your patch filename in the `patchList` list in `./server/database.js`
|
||||||
|
|
||||||
# Unit Test
|
# Unit Test
|
||||||
|
|
||||||
|
|
5
jest-puppeteer.config.js
Normal file
5
jest-puppeteer.config.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module.exports = {
|
||||||
|
"launch": {
|
||||||
|
"headless": false
|
||||||
|
}
|
||||||
|
};
|
6171
package-lock.json
generated
6171
package-lock.json
generated
File diff suppressed because it is too large
Load diff
14
package.json
14
package.json
|
@ -20,6 +20,8 @@
|
||||||
"start-server": "node server/server.js",
|
"start-server": "node server/server.js",
|
||||||
"start-server-dev": "cross-env NODE_ENV=development node server/server.js",
|
"start-server-dev": "cross-env NODE_ENV=development node server/server.js",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
"prepare-test": "npm run build && node server/server.js --port=3002 --data-dir=./data/test/",
|
||||||
|
"test": "jest",
|
||||||
"tsc": "tsc",
|
"tsc": "tsc",
|
||||||
"vite-preview-dist": "vite preview --host",
|
"vite-preview-dist": "vite preview --host",
|
||||||
"build-docker": "npm run build-docker-debian && npm run build-docker-alpine",
|
"build-docker": "npm run build-docker-debian && npm run build-docker-alpine",
|
||||||
|
@ -104,10 +106,22 @@
|
||||||
"dns2": "~2.0.1",
|
"dns2": "~2.0.1",
|
||||||
"eslint": "~7.32.0",
|
"eslint": "~7.32.0",
|
||||||
"eslint-plugin-vue": "~7.18.0",
|
"eslint-plugin-vue": "~7.18.0",
|
||||||
|
"jest": "~27.2.4",
|
||||||
|
"jest-puppeteer": "~6.0.0",
|
||||||
|
"puppeteer": "~10.4.0",
|
||||||
"sass": "~1.42.1",
|
"sass": "~1.42.1",
|
||||||
"stylelint": "~13.13.1",
|
"stylelint": "~13.13.1",
|
||||||
"stylelint-config-standard": "~22.0.0",
|
"stylelint-config-standard": "~22.0.0",
|
||||||
"typescript": "~4.4.3",
|
"typescript": "~4.4.3",
|
||||||
"vite": "~2.5.10"
|
"vite": "~2.5.10"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"verbose": true,
|
||||||
|
"preset": "jest-puppeteer",
|
||||||
|
"globals": {
|
||||||
|
"__DEV__": true
|
||||||
|
},
|
||||||
|
"testRegex": "./test/*.spec.js",
|
||||||
|
"rootDir": "."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ exports.startInterval = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.latestVersion = res.data.version;
|
exports.latestVersion = res.data.version;
|
||||||
console.log("Latest Version: " + exports.latestVersion);
|
|
||||||
} catch (_) { }
|
} catch (_) { }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
21
test/test.spec.js
Normal file
21
test/test.spec.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
beforeAll(() => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
return console.log("Cleanup");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Very Simple Test", () => {
|
||||||
|
|
||||||
|
const title = "Uptime Kuma";
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await page.goto("http://127.0.0.1:3002");
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should be titled "${title}"`, async () => {
|
||||||
|
await expect(page.title()).resolves.toMatch(title);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue