mirror of
https://github.com/Lissy93/dashy.git
synced 2026-07-30 11:06:09 -04:00
* feat: add ICMP ping check support to item * Replaced ping package with pingman package to be compliant with Dashy CI NodeJS version (20). Fixed a behavior bug in status indicator component which didn't changed icon to yellow when checking. Made otherStatusText a computed field to make it reflecting dynamically a new check request. Added more examples to default conf.yml * Removed a forgotten trace to console * Made changes requested by Lissy after review of the PR. Corrected tests using localhost which is not a valid host for pingman. Added a Validator.js file in src/utils with function to check validity of hosts. Reverted conf.yml file to the original version. * Fixed a problem in configuration of pingman call after adding support of IPV6 addresses. * Updated Dockerfile to pass Docker smoke tests in CI * Revert to latest version of `user-data/conf.yml` from `master` * Removed the duplicated feature line for ping check and just added `hosts` to the existing one * Removed the unused `shouldEnabledPingCheck` function * Add the ping system package and give rights to use to the node user so the pingman module can work in Docker container * Remove `src/utils/Validator.js` file. Rely on `pingman` internal validation of hostname instead to avoid command injection.
136 lines
4.0 KiB
JavaScript
136 lines
4.0 KiB
JavaScript
import { defineConfig } from 'vite';
|
|
import vue from '@vitejs/plugin-vue';
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
import svgLoader from 'vite-svg-loader';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { readFileSync, copyFileSync, existsSync, readdirSync } from 'fs';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const pkg = JSON.parse(readFileSync(path.resolve(__dirname, 'package.json'), 'utf-8'));
|
|
const userDataDir = path.resolve(__dirname, process.env.USER_DATA_DIR || 'user-data');
|
|
|
|
function serveUserData() {
|
|
return {
|
|
name: 'serve-user-data',
|
|
configureServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
if (!req.url) return next();
|
|
const filePath = path.join(userDataDir, req.url.split('?')[0]);
|
|
try {
|
|
const content = readFileSync(filePath);
|
|
const ext = path.extname(filePath);
|
|
const types = { '.yml': 'text/yaml', '.yaml': 'text/yaml', '.json': 'application/json', '.png': 'image/png', '.svg': 'image/svg+xml' };
|
|
res.setHeader('Content-Type', types[ext] || 'application/octet-stream');
|
|
res.end(content);
|
|
} catch {
|
|
next();
|
|
}
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
function copyUserDataConfig() {
|
|
return {
|
|
name: 'copy-user-data-config',
|
|
closeBundle() {
|
|
const outDir = path.resolve(__dirname, 'dist');
|
|
if (!existsSync(userDataDir)) return;
|
|
const ymlFiles = readdirSync(userDataDir).filter(f => f.endsWith('.yml') || f.endsWith('.yaml'));
|
|
for (const file of ymlFiles) {
|
|
const src = path.join(userDataDir, file);
|
|
const dest = path.join(outDir, file);
|
|
copyFileSync(src, dest);
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
envPrefix: ['VITE_', 'DASHY_'],
|
|
plugins: [
|
|
vue(),
|
|
svgLoader(),
|
|
serveUserData(),
|
|
copyUserDataConfig(),
|
|
VitePWA({
|
|
registerType: 'prompt',
|
|
useCredentials: true,
|
|
manifest: {
|
|
name: 'Dashy',
|
|
theme_color: '#00af87',
|
|
background_color: '#0b1021',
|
|
icons: [
|
|
{ src: '/web-icons/favicon-64x64.png', sizes: '64x64', type: 'image/png' },
|
|
{ src: '/web-icons/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
|
|
{ src: '/web-icons/favicon-16x16.png', sizes: '16x16', type: 'image/png' },
|
|
{ src: '/web-icons/dashy-logo.png', sizes: '512x512', type: 'image/png' },
|
|
],
|
|
},
|
|
workbox: {
|
|
cleanupOutdatedCaches: true,
|
|
clientsClaim: true,
|
|
skipWaiting: false,
|
|
navigateFallback: '/index.html',
|
|
navigateFallbackDenylist: [
|
|
/^\/(status-check|ping-check|system-info|cors-proxy|get-user|config-manager)\b/,
|
|
],
|
|
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
|
|
globIgnores: [
|
|
'**/*.map',
|
|
'**/manifest*.js',
|
|
'**/.nojekyll',
|
|
'**/.gitignore',
|
|
'**/*.yml',
|
|
'**/*.yaml',
|
|
],
|
|
runtimeCaching: [
|
|
{
|
|
urlPattern: /\.ya?ml(\?.*)?$/i,
|
|
handler: 'NetworkFirst',
|
|
options: {
|
|
cacheName: 'dashy-config',
|
|
networkTimeoutSeconds: 3,
|
|
expiration: { maxEntries: 20, maxAgeSeconds: 60 * 60 * 24 },
|
|
cacheableResponse: { statuses: [200] },
|
|
},
|
|
},
|
|
{
|
|
urlPattern: /\/(status-check|system-info|cors-proxy|get-user|config-manager)\b/,
|
|
handler: 'NetworkOnly',
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
],
|
|
|
|
resolve: {
|
|
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
|
|
define: {
|
|
'import.meta.env.VITE_APP_VERSION': JSON.stringify(pkg.version),
|
|
},
|
|
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
silenceDeprecations: ['import', 'legacy-js-api'],
|
|
},
|
|
},
|
|
},
|
|
|
|
build: {
|
|
outDir: 'dist',
|
|
chunkSizeWarningLimit: 7000,
|
|
},
|
|
|
|
server: {
|
|
port: 8080,
|
|
},
|
|
});
|