mirror of
https://github.com/Lissy93/dashy.git
synced 2025-12-22 16:33:29 +01:00
connect the real api
This commit is contained in:
parent
286f13e067
commit
ead21a2fc6
2 changed files with 19 additions and 115 deletions
|
|
@ -90,13 +90,7 @@ export default {
|
|||
: this.endpoint;
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Fetching data from:', url);
|
||||
const res = await fetch(url, {
|
||||
method: 'GET',
|
||||
mode: 'cors',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('API Response - CPU:', data.cpu?.total, 'MEM:', data.mem?.percent, 'LOAD:', data.load?.min1);
|
||||
|
|
@ -137,14 +131,14 @@ export default {
|
|||
// eslint-disable-next-line no-console
|
||||
console.error('Glances API Error:', e);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Using fallback data');
|
||||
// 使用模拟数据
|
||||
this.cpu = Math.random() * 10 + 2;
|
||||
this.memory = Math.random() * 30 + 20;
|
||||
this.load = Math.random() * 3 + 0.5;
|
||||
this.cpuUser = Math.random() * 5 + 1;
|
||||
this.cpuSystem = Math.random() * 3 + 0.5;
|
||||
this.cpuIowait = Math.random() * 2;
|
||||
console.log('Using fallback data - API connection failed');
|
||||
// API失败时的后备数据
|
||||
this.cpu = 0;
|
||||
this.memory = 0;
|
||||
this.load = 0;
|
||||
this.cpuUser = 0;
|
||||
this.cpuSystem = 0;
|
||||
this.cpuIowait = 0;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
110
vue.config.js
110
vue.config.js
|
|
@ -1,103 +1,13 @@
|
|||
/**
|
||||
* Dashy is built using Vue (2). This is the main Vue and Webpack configuration
|
||||
*
|
||||
* User Configurable Options:
|
||||
* - NODE_ENV: Sets the app mode (production, development, test).
|
||||
* - BASE_URL: Root URL for the app deployment (defaults to '/').
|
||||
* - INTEGRITY: Enables SRI, set to 'true' to activate.
|
||||
* - USER_DATA_DIR: Sets an alternative dir for user data (defaults ./user-data).
|
||||
* - IS_DOCKER: Indicates if running in a Docker container.
|
||||
* - IS_SERVER: Indicates if running as a server (as opposed to static build).
|
||||
*
|
||||
* Documentation:
|
||||
* - Vue CLI Config options: https://cli.vuejs.org/config
|
||||
* - For Dashy docs, see the repo: https://github.com/lissy93/dashy
|
||||
*
|
||||
* Note: ES7 syntax is not supported in this configuration context.
|
||||
* Licensed under the MIT License, (C) Alicia Sykes 2024 (see LICENSE for details).
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
|
||||
// Get app mode: production, development, or test
|
||||
const mode = process.env.NODE_ENV || 'production';
|
||||
|
||||
// Get current version
|
||||
process.env.VUE_APP_VERSION = require('./package.json').version;
|
||||
|
||||
// Get default info for PWA
|
||||
const { pwa } = require('./src/utils/defaults');
|
||||
|
||||
// Get base URL
|
||||
const publicPath = process.env.BASE_URL || '/';
|
||||
|
||||
// Should enable Subresource Integrity (SRI) on link and script tags
|
||||
const integrity = process.env.INTEGRITY === 'true';
|
||||
|
||||
// If neither env vars are set, then it's a static build
|
||||
const isServer = process.env.IS_DOCKER || process.env.IS_SERVER || false;
|
||||
|
||||
// Use copy-webpack-plugin to copy user-data to dist IF not running as a server
|
||||
const plugins = !isServer ? [
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{ from: './user-data', to: './' },
|
||||
],
|
||||
}),
|
||||
] : [];
|
||||
|
||||
// Webpack Config
|
||||
const configureWebpack = {
|
||||
devtool: 'source-map',
|
||||
mode,
|
||||
plugins,
|
||||
module: {
|
||||
rules: [
|
||||
{ test: /.svg$/, loader: 'vue-svg-loader' },
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
loader: 'ts-loader',
|
||||
options: { appendTsSuffixTo: [/\.vue$/] },
|
||||
},
|
||||
],
|
||||
},
|
||||
performance: {
|
||||
maxEntrypointSize: 10000000,
|
||||
maxAssetSize: 10000000,
|
||||
},
|
||||
};
|
||||
|
||||
// Development server config
|
||||
const devServer = {
|
||||
contentBase: [
|
||||
path.join(__dirname, 'public'),
|
||||
path.join(__dirname, process.env.USER_DATA_DIR || 'user-data'),
|
||||
],
|
||||
watchContentBase: true,
|
||||
publicPath: '/',
|
||||
};
|
||||
|
||||
// Application pages
|
||||
const pages = {
|
||||
dashy: {
|
||||
entry: 'src/main.js',
|
||||
filename: 'index.html',
|
||||
},
|
||||
};
|
||||
|
||||
// Export the main Vue app config
|
||||
module.exports = {
|
||||
publicPath,
|
||||
pwa,
|
||||
integrity,
|
||||
configureWebpack,
|
||||
pages,
|
||||
devServer,
|
||||
chainWebpack: config => {
|
||||
config.module.rules.delete('svg');
|
||||
config.cache({
|
||||
type: 'filesystem',
|
||||
});
|
||||
pages: {
|
||||
index: {
|
||||
entry: 'src/main.js',
|
||||
template: 'public/index.html',
|
||||
filename: 'index.html',
|
||||
},
|
||||
},
|
||||
devServer: {
|
||||
port: 8080,
|
||||
host: '0.0.0.0',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue