mirror of
https://github.com/hexboy/maven-mirror-tool.git
synced 2025-04-25 16:09:08 +00:00
print served endpoints on start serving
This commit is contained in:
parent
86c118059a
commit
2fe313b696
2 changed files with 37 additions and 3 deletions
|
@ -13,7 +13,7 @@ import {
|
|||
IGNORE_FILES,
|
||||
VALID_FILE_TYPES,
|
||||
} from './config';
|
||||
import { getCachedServer } from './utils';
|
||||
import { getCachedServer, printServedEndpoints } from './utils';
|
||||
import { GotDownloader } from './downloader/got';
|
||||
|
||||
const downloader = new GotDownloader();
|
||||
|
@ -78,7 +78,6 @@ if (VERBOSE) {
|
|||
}
|
||||
app.get('*', cacheRequestHandler);
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Serving! http://0.0.0.0:${PORT}/${DEFAULT_PATH}\n`);
|
||||
console.log('add this ⬇️ in build.gradle');
|
||||
console.log(
|
||||
chalk.green(
|
||||
|
@ -88,9 +87,11 @@ app.listen(PORT, () => {
|
|||
console.log('\nadd this ⬇️ in build.gradle.kts');
|
||||
console.log(
|
||||
chalk.green(
|
||||
`maven { url = uri("http://127.0.0.1:${PORT}/${DEFAULT_PATH}")\nisAllowInsecureProtocol = true }`
|
||||
`maven {\n url = uri("http://127.0.0.1:${PORT}/${DEFAULT_PATH}")\n isAllowInsecureProtocol = true\n}`
|
||||
)
|
||||
);
|
||||
|
||||
printServedEndpoints(PORT, DEFAULT_PATH);
|
||||
});
|
||||
|
||||
// help:
|
||||
|
|
33
src/utils.ts
33
src/utils.ts
|
@ -1,4 +1,5 @@
|
|||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
|
||||
import { CACHE_DIR, REPOSITORIES } from './config';
|
||||
|
@ -13,3 +14,35 @@ export const getCachedServer = (filePath: string) => {
|
|||
});
|
||||
return srv;
|
||||
};
|
||||
|
||||
export const printServedEndpoints = (port: number | string, urlPath: string) => {
|
||||
try {
|
||||
const interfaces = os.networkInterfaces();
|
||||
const list = Object.keys(interfaces)
|
||||
.map((name) =>
|
||||
(interfaces[name] || []).filter((item) => item.family === 'IPv4')
|
||||
)
|
||||
.filter((l) => l.length > 0)
|
||||
.flat();
|
||||
const localInterface = list.find((item) => item.internal);
|
||||
const networkInterface = list.find((item) => !item.internal);
|
||||
console.log('\n🚀 Serving!');
|
||||
console.log('--------------------------------------------');
|
||||
console.log(`Local: http://0.0.0.0:${port}/${urlPath}`);
|
||||
if (localInterface) {
|
||||
console.log(`Local: http://${localInterface.address}:${port}/${urlPath}`);
|
||||
}
|
||||
if (networkInterface) {
|
||||
console.log(
|
||||
`Network: http://${networkInterface.address}:${port}/${urlPath}`
|
||||
);
|
||||
}
|
||||
console.log('--------------------------------------------');
|
||||
} catch (error) {
|
||||
console.log('\n🚀 Serving!');
|
||||
console.log('--------------------------------------------');
|
||||
console.log(`Local: http://0.0.0.0:${port}/${urlPath}`);
|
||||
console.log(`Local: http://127.0.0.1:${port}/${urlPath}`);
|
||||
console.log('--------------------------------------------');
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue