Repository: louislam/uptime-kuma
File: server/notification.js (JavaScript)

Code before:

                await axios.post(notification.webhookURL, finalData, config)
                return okMsg;

            } catch (error) {
                throwGeneralAxiosError(error)
            }

        } else if (notification.type === "smtp") {
            return await Notification.smtp(notification, msg)

        } else if (notification.type === "discord") {
            try {
                const discordDisplayName = notification.discordUsername || "Uptime Kuma";

                // If heartbeatJSON is null, assume we're testing.
                if (heartbeatJSON == null) {
                    let discordtestdata = {
                        username: discordDisplayName,
                        content: msg,
                    }
                    await axios.post(notification.discordWebhookUrl, discordtestdata)
                    return okMsg;
                }
                let url = monitorJSON["url"] === "https://" ? monitorJSON["hostname"] : monitorJSON["url"]
                if (monitorJSON["port"]) url += ":" + monitorJSON[port]

                // If heartbeatJSON is not null, we go into the normal alerting loop.
                if (heartbeatJSON["status"] == 0) {
                    let discorddowndata = {
                        username: discordDisplayName,
                        embeds: [{
                            title: "❌ Your service " + monitorJSON["name"] + " went down. ❌",
                            color: 16711680,
                            timestamp: heartbeatJSON["time"],
                            fields: [
                                {
                                    name: "Service Name",
                                    value: monitorJSON["name"],
                                },
                                {
                                    name: "Service URL",
                                    value: url,
                                },
                                {
                                    name: "Time (UTC)",
                                    value: heartbeatJSON["time"],
                                },
                                {
                                    name: "Error",
                                    value: heartbeatJSON["msg"],

Review comment (suggestion):
```suggestion

                let url = monitorJSON["url"] === "https://" ? monitorJSON["hostname"] : monitorJSON["url"]
                if (monitorJSON["port"]) {
                    url += ":" + monitorJSON[port];
                }
```

Code after:

                await axios.post(notification.webhookURL, finalData, config)
                return okMsg;

            } catch (error) {
                throwGeneralAxiosError(error)
            }

        } else if (notification.type === "smtp") {
            return await Notification.smtp(notification, msg)

        } else if (notification.type === "discord") {
            try {
                const discordDisplayName = notification.discordUsername || "Uptime Kuma";

                // If heartbeatJSON is null, assume we're testing.
                if (heartbeatJSON == null) {
                    let discordtestdata = {
                        username: discordDisplayName,
                        content: msg,
                    }
                    await axios.post(notification.discordWebhookUrl, discordtestdata)
                    return okMsg;
                }

                let url = monitorJSON["url"] === "https://" ? monitorJSON["hostname"] : monitorJSON["url"]
                if (monitorJSON["port"]) {
                    url += ":" + monitorJSON[port];
                }

                // If heartbeatJSON is not null, we go into the normal alerting loop.
                if (heartbeatJSON["status"] == 0) {
                    let discorddowndata = {
                        username: discordDisplayName,
                        embeds: [{
                            title: "❌ Your service " + monitorJSON["name"] + " went down. ❌",
                            color: 16711680,
                            timestamp: heartbeatJSON["time"],
                            fields: [
                                {
                                    name: "Service Name",
                                    value: monitorJSON["name"],
                                },
                                {
                                    name: "Service URL",
                                    value: url,
                                },
                                {
                                    name: "Time (UTC)",
                                    value: heartbeatJSON["time"],
                                },