shareoverlan
Version:
Simple local file sharing over LAN.
88 lines (85 loc) • 3.64 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.currentPath = void 0;
exports.default = startServer;
const express_1 = __importDefault(require("express"));
const cors_1 = __importDefault(require("cors"));
const body_parser_1 = __importDefault(require("body-parser"));
const qrcode_1 = __importDefault(require("qrcode"));
const path_1 = __importDefault(require("path"));
const update_notifier_1 = __importDefault(require("update-notifier"));
const GetLocalIpAdress_1 = __importDefault(require("./extra/GetLocalIpAdress"));
const fileRoutes_1 = __importDefault(require("./routes/fileRoutes"));
const package_json_1 = __importDefault(require("../package.json"));
exports.currentPath = "./";
const currentVersion = package_json_1.default.version;
function startServer(DevMode = false) {
const notifier = (0, update_notifier_1.default)({ pkg: package_json_1.default });
notifier.notify();
const args = process.argv.slice(2);
let port;
let devMode = DevMode;
let disableQRCode = false;
args.forEach((arg, index) => {
if (arg.toLowerCase() === '--port' || arg.toLowerCase() === '-p') {
port = args[index + 1];
}
if (arg.toLowerCase() === '--dev') {
devMode = true;
}
if (arg.toLowerCase() === '--disable-qrcode') {
console.log("Disabling QR Code generation in terminal");
disableQRCode = true;
}
if (arg.toLowerCase() === "--version" || arg.toLowerCase() === "-v") {
console.log(`
ShareoverLAN version : ${currentVersion}
`);
process.exit(0);
}
if (arg.toLowerCase() === "--help" || arg.toLowerCase() === "-h") {
console.log(`
Usage: shareoverlan [options]
Options:
--port, -p <port> Specify the port to run the server on (default: 6969)
--version, -v Show the current version of ShareoverLAN
--disable-qrcode Disable QR code generation in terminal (default: false)
`);
process.exit(0);
}
;
});
const localIpAddress = (0, GetLocalIpAdress_1.default)();
const PORT = port !== null && port !== void 0 ? port : 6969;
const app = (0, express_1.default)();
app.use(body_parser_1.default.urlencoded({ extended: true }));
app.use(body_parser_1.default.json());
app.use((0, cors_1.default)());
app.use('/download', express_1.default.static('.'));
app.use(express_1.default.static(path_1.default.join(__dirname, "../", 'client')));
const publicFolder = exports.currentPath;
app.use('/public', express_1.default.static(publicFolder, {
dotfiles: 'allow',
}));
app.get('/', (req, res) => {
res.sendFile(path_1.default.join(__dirname, "../", 'client', 'index.html'));
});
app.use('/api/v1/', fileRoutes_1.default);
app.listen(PORT, () => {
console.log("✅ shareoverlan CLI running!");
console.log("Server is Listening at:");
console.log(`--> Local: http://localhost:${PORT}`);
localIpAddress.forEach((el) => {
console.log(`--> Network: http://${el}:${PORT}`);
if (devMode || !disableQRCode) {
qrcode_1.default.toString(`http://${el}:${PORT}`, { type: 'terminal' }, function (err, url) {
console.log(url);
});
}
});
});
}
//# sourceMappingURL=index.js.map