Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle: 通过域名 `siyuan.localhost` 加载 https://github.com/siyuan-note/siyuan/issues/6368

Liang Ding8bc889659bdb
diff --git a/app/appearance/boot/index.html b/app/appearance/boot/index.html
index 75569556d8..6923f5b6cd 100644
--- a/app/appearance/boot/index.html
+++ b/app/appearance/boot/index.html
@@ -100,7 +100,7 @@
return new Promise(resolve => setTimeout(resolve, ms))
}
const redirect = () => {
- const uri = 'http://127.0.0.1:' + location.port
+ const uri = 'http://siyuan.localhost:' + location.port
if (navigator.userAgent.match(/Android/i))
document.location = uri
else
@@ -113,7 +113,7 @@
let progressing = false
while (!progressing) {
try {
- const progressResult = await fetch('http://127.0.0.1:' + location.port + '/api/system/bootProgress')
+ const progressResult = await fetch('http://siyuan.localhost:' + location.port + '/api/system/bootProgress')
const progressData = await progressResult.json()
document.getElementById('progress').style.width = progressData.data.progress + '%'
document.getElementById('details').textContent = progressData.data.details
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index b568c6f117..1f119a567c 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -689,7 +689,7 @@
"about": "About",
"about1": "Copyright (c) 2020-present • Yunnan Liandi Technology Co., Ltd. • <a target='_blank' href='https://b3log.org/siyuan/privacy.html'>Privacy Policy</a> • <a target='_blank' href='https://b3log.org/siyuan/eula.html'>User Agreement</a><div class='fn__hr'></div><div class='fn__hr'></div><div class='ft__on-surface'>The core developers of SiYuan are <a href=\"https://github.com/88250\" target=\"_blank\">D</a> and <a href=\"https://github.com/Vanessa219\" target=\"_blank\">V</a>, and the community development contributors can be seen <a href=\"https://github.com/siyuan-note/bazaar/graphs/contributors\" target=\"_blank\">here</a></div>",
"about2": "Use on browser",
- "about3": "Please use the Chrome browser and keep it in the same network as the computer, port <code class='fn__code'>${port}</code>, the IP addresses that may be connected are as follows",
+ "about3": "Please use the Chrome browser and keep it in the same network as the computer, port <code class='fn__code'>${port}</code>, the addresses that may be connected are as follows: ",
"about4": "Open browser",
"about5": "Access Authorization Code",
"about6": "After configuration, it will be used as the access authentication password, leave it blank to close the authentication",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index 275a007898..fbb9a066e3 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -689,7 +689,7 @@
"about": "Acerca de",
"about1": "Copyright (c) 2020-presente • Yunnan Liandi Technology Co., Ltd. • <a target='_blank' href='https://b3log.org/siyuan/privacy.html'>Política de privacidad</a> • <a target='_blank' href='https://b3log.org/siyuan/eula.html'>Acuerdo de usuario</a><div class='fn__hr'></div><div class='fn__hr'></div><div class='ft__on-surface'>Los principales desarrolladores de SiYuan son <a href=\"https://github.com/88250\" target=\"_blank\">D</a> y <a href=\"https://github.com/Vanessa219\" target=\"_blank\">V</a>, y los contribuyentes al desarrollo de la comunidad pueden verse <a href=\"https://github.com/siyuan-note/bazaar/graphs/contributors\" target=\"_blank\">aquí</a></div>",
"about2": "Uso en el navegador",
- "about3": "Por favor, utilice el navegador Chrome y manténgalo en la misma red que el ordenador, puerto <code class='fn__code'>${port}</code>, las direcciones IP que pueden conectarse son las siguientes",
+ "about3": "Por favor, utilice el navegador Chrome y manténgalo en la misma red que el ordenador, puerto <code class='fn__code'>${port}</code>, las direcciones que se pueden conectar son las siguientes: ",
"about4": "Abrir el navegador",
"about5": "Código de autorización de acceso",
"about6": "Después de la configuración, se utilizará como contraseña de autenticación de acceso, déjelo en blanco para cerrar la autenticación",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index ce7d1b0be9..015bea5962 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -689,7 +689,7 @@
"about": "À propos de",
"about1": "Copyright (c) 2020-présent • Yunnan Liandi Technology Co., Ltd. • <a target='_blank' href='https://b3log.org/siyuan/privacy.html'>Politique de confidentialité</a> • <a target='_blank' href='https://b3log.org/siyuan/eula.html'>Accord de l'utilisateur</a><div class='fn__hr'></div><div class='fn__hr'></div><div class='ft__on-surface'>Les principaux développeurs de SiYuan sont <a href=\"https://github.com/88250\" target=\"_blank\">D</a> et <a href=\"https://github.com/Vanessa219\" target=\"_blank\">V</a>, et les contributeurs au développement de la communauté peuvent être vus <a href=\"https://github.com/siyuan-note/bazaar/graphs/contributors\" target=\"_blank\">ici</a></div>",
"about2": "Utiliser sur le navigateur",
- "about3": "Veuillez utiliser le navigateur Chrome et le garder sur le même réseau que l'ordinateur, port <code class='fn__code'>${port}</code>, les adresses IP pouvant être connectées sont les suivantes",
+ "about3": "Veuillez utiliser le navigateur Chrome et le garder sur le même réseau que l'ordinateur, port <code class='fn__code'>${port}</code>, les adresses pouvant être connectées sont les suivantes: ",
"about4": "Ouvrir le navigateur",
"about5": "Accès Code d'autorisation",
"about6": "Configuré comme mot de passe d'authentification d'accès, laisser vide pour désactiver l'authentification.",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index 568a7a7979..72b8f2996a 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -689,7 +689,7 @@
"about": "關於",
"about1": "版權所有 (c) 2020-現在 • 雲南鏈滴科技有限公司 • <a target='_blank' href='https://b3log.org/siyuan/privacy.html'>隱私政策</a> • <a target='_blank' href='https://b3log.org/siyuan/eula.html'>用戶協議</a><div class='fn__hr'></div><div class='fn__hr'></div><div class='ft__on-surface'>思源筆記的核心開發者是 <a href=\"https://github.com/88250\" target=\"_blank\">D</a> 和 <a href=\"https://github.com/Vanessa219\" target=\"_blank\">V</a>,社區開發貢獻者可在<a href=\"https://github.com/siyuan-note/bazaar/graphs/contributors\" target=\"_blank\">這裡</a>看到</div>",
"about2": "在瀏覽器上使用",
- "about3": "請使用 Chrome 瀏覽器並保持和電腦在同一個網路內,端口 <code class='fn__code'>${port}</code>,可能連通的 IP 地址如下",
+ "about3": "請使用 Chrome 瀏覽器並保持和電腦在同一個網路內,端口 <code class='fn__code'>${port}</code>,可能連通的網絡地址:",
"about4": "打開瀏覽器",
"about5": "存取授權碼",
"about6": "配置後作為存取鑒權密碼,留空則關閉鑒權",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index 0c0c1ed090..81c488936e 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -689,7 +689,7 @@
"about": "关于",
"about1": "版权所有 (c) 2020-现在 • 云南链滴科技有限公司 • <a target='_blank' href='https://b3log.org/siyuan/privacy.html'>隐私政策</a> • <a target='_blank' href='https://b3log.org/siyuan/eula.html'>用户协议</a><div class='fn__hr'></div><div class='fn__hr'></div><div class='ft__on-surface'>思源笔记的核心开发者是 <a href=\"https://ld246.com/member/88250\" target=\"_blank\">D</a> 和 <a href=\"https://ld246.com/member/Vanessa\" target=\"_blank\">V</a>,社区开发贡献者可在<a href=\"https://github.com/siyuan-note/bazaar/graphs/contributors\" target=\"_blank\">这里</a>看到</div>",
"about2": "在浏览器上使用",
- "about3": "请使用 Chrome 浏览器并保持和电脑在同一个网络内,端口 <code class='fn__code'>${port}</code>,可能连通的 IP 地址:",
+ "about3": "请使用 Chrome 浏览器并保持和电脑在同一个网络内,端口 <code class='fn__code'>${port}</code>,可能连通的网络地址:",
"about4": "打开浏览器",
"about5": "访问授权码",
"about6": "配置后作为访问鉴权密码,留空则关闭鉴权",
diff --git a/app/electron/main.js b/app/electron/main.js
index 9ccf9f604a..b5dcca43bc 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -43,6 +43,7 @@ let siyuanOpenURL
let firstOpen = false
let resetWindowStateOnRestart = false
let kernelPort = "6806"
+const localhost = "siyuan.localhost"
require('@electron/remote/main').initialize()
if (!app.requestSingleInstanceLock()) {
@@ -50,6 +51,10 @@ if (!app.requestSingleInstanceLock()) {
return
}
+const getServer = () => {
+ return "http://" + localhost + ":" + kernelPort
+}
+
const showErrorWindow = (title, content) => {
let errorHTMLPath = path.join(appDir, 'app', 'electron', 'error.html')
if (isDevEnv) {
@@ -266,7 +271,7 @@ const boot = () => {
})
// 加载主界面
- mainWindow.loadURL('http://127.0.0.1:' + kernelPort + '/stage/build/app/index.html?v=' +
+ mainWindow.loadURL(getServer() + '/stage/build/app/index.html?v=' +
new Date().getTime())
// 菜单
@@ -330,7 +335,7 @@ const boot = () => {
Menu.setApplicationMenu(menu)
// 当前页面链接使用浏览器打开
mainWindow.webContents.on('will-navigate', (event, url) => {
- if (url.startsWith('http://127.0.0.1:' + kernelPort)) {
+ if (url.startsWith(getServer())) {
return
}
@@ -399,7 +404,7 @@ const boot = () => {
theme: nativeTheme.shouldUseDarkColors ? 'dark' : 'light',
init: true,
})
- await fetch('http://127.0.0.1:' + kernelPort + '/api/system/uiproc?pid=' + process.pid,
+ await fetch(getServer() + '/api/system/uiproc?pid=' + process.pid,
{method: 'POST'})
})
ipcMain.on('siyuan-hotkey', (event, hotkey) => {
@@ -632,11 +637,11 @@ const initKernel = (initData) => {
writeLog('checking kernel version')
while (!gotVersion) {
try {
- const apiResult = await fetch('http://127.0.0.1:' + kernelPort + '/api/system/version')
+ const apiResult = await fetch(getServer() + '/api/system/version')
apiData = await apiResult.json()
gotVersion = true
bootWindow.setResizable(false)
- bootWindow.loadURL('http://127.0.0.1:' + kernelPort + '/appearance/boot/index.html')
+ bootWindow.loadURL(getServer() + '/appearance/boot/index.html')
bootWindow.show()
} catch (e) {
writeLog('get kernel version failed: ' + e.message)
@@ -656,14 +661,14 @@ const initKernel = (initData) => {
if (!isDevEnv && apiData.data !== appVer) {
writeLog(
`kernel [${apiData.data}] is running, shutdown it now and then start kernel [${appVer}]`)
- fetch('http://127.0.0.1:' + kernelPort + '/api/system/exit', {method: 'POST'})
+ fetch(getServer() + '/api/system/exit', {method: 'POST'})
bootWindow.destroy()
resolve(false)
} else {
let progressing = false
while (!progressing) {
try {
- const progressResult = await fetch('http://127.0.0.1:' + kernelPort + '/api/system/bootProgress')
+ const progressResult = await fetch(getServer() + '/api/system/bootProgress')
const progressData = await progressResult.json()
if (progressData.data.progress >= 100) {
resolve(true)
@@ -673,7 +678,7 @@ const initKernel = (initData) => {
}
} catch (e) {
writeLog('get boot progress failed: ' + e.message)
- fetch('http://127.0.0.1:' + kernelPort + '/api/system/exit', {method: 'POST'})
+ fetch(getServer() + '/api/system/exit', {method: 'POST'})
bootWindow.destroy()
resolve(false)
progressing = true
@@ -804,15 +809,15 @@ const cp = require("child_process");
powerMonitor.on('suspend', () => {
writeLog('system suspend')
- fetch('http://127.0.0.1:' + kernelPort + '/api/sync/performSync', {method: 'POST'})
+ fetch(getServer() + '/api/sync/performSync', {method: 'POST'})
})
powerMonitor.on('resume', () => {
writeLog('system resume')
- fetch('http://127.0.0.1:' + kernelPort + '/api/sync/performSync', {method: 'POST'})
+ fetch(getServer() + '/api/sync/performSync', {method: 'POST'})
})
powerMonitor.on('shutdown', () => {
writeLog('system shutdown')
- fetch('http://127.0.0.1:' + kernelPort + '/api/system/exit', {method: 'POST'})
+ fetch(getServer() + '/api/system/exit', {method: 'POST'})
})
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20201004194026-s8h2cog.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20201004194026-s8h2cog.sy
index a886023d30..a65a8096a5 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20201004194026-s8h2cog.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20201004194026-s8h2cog.sy
@@ -75,7 +75,7 @@
{
"Type": "NodeTextMark",
"TextMarkType": "code",
- "TextMarkTextContent": "127.0.0.1"
+ "TextMarkTextContent": "siyuan.localhost"
},
{
"Type": "NodeText",
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20201004184819-nj8ibyg.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20201004184819-nj8ibyg.sy
index ed872cd16b..a2c4285c83 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20201004184819-nj8ibyg.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20201004184819-nj8ibyg.sy
@@ -76,7 +76,7 @@
{
"Type": "NodeTextMark",
"TextMarkType": "code",
- "TextMarkTextContent": "127.0.0.1"
+ "TextMarkTextContent": "siyuan.localhost"
},
{
"Type": "NodeText",
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122523-rl8356a.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122523-rl8356a.sy
index a176270b60..ed99696322 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122523-rl8356a.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122523-rl8356a.sy
@@ -75,7 +75,7 @@
{
"Type": "NodeTextMark",
"TextMarkType": "code",
- "TextMarkTextContent": "127.0.0.1"
+ "TextMarkTextContent": "siyuan.localhost"
},
{
"Type": "NodeText",
diff --git a/app/src/config/about.ts b/app/src/config/about.ts
index 9f00c719ea..13baccb1ff 100644
--- a/app/src/config/about.ts
+++ b/app/src/config/about.ts
@@ -55,7 +55,7 @@ export const about = {
<span class="b3-label__text"><code class="fn__code">${window.siyuan.config.localIPs.join("</code> <code class='fn__code'>")}</code></span>
</div>
<div class="fn__space"></div>
- <button data-type="open" data-url="http://${window.siyuan.config.system.networkServe ? window.siyuan.config.localIPs[0] : "127.0.0.1"}:${location.port}" class="b3-button b3-button--outline fn__size200 fn__flex-center">
+ <button data-type="open" data-url="http://${window.siyuan.config.system.networkServe ? window.siyuan.config.localIPs[0] : "siyuan.localhost"}:${location.port}" class="b3-button b3-button--outline fn__size200 fn__flex-center">
<svg><use xlink:href="#iconLink"></use></svg>${window.siyuan.languages.about4}
</button>
</label>
diff --git a/app/src/mobile/util/menu.ts b/app/src/mobile/util/menu.ts
index df20a55ccb..28f551a7ee 100644
--- a/app/src/mobile/util/menu.ts
+++ b/app/src/mobile/util/menu.ts
@@ -177,7 +177,7 @@ ${accountHTML}
closePanel();
if (!window.siyuan.config.localIPs || window.siyuan.config.localIPs.length === 0 ||
(window.siyuan.config.localIPs.length === 1 && window.siyuan.config.localIPs[0] === "")) {
- window.siyuan.config.localIPs = ["127.0.0.1"];
+ window.siyuan.config.localIPs = ["siyuan.localhost"];
}
modelElement.style.top = "0";
modelElement.querySelector(".toolbar__icon").innerHTML = '<use xlink:href="#iconInfo"></use>';
@@ -193,7 +193,7 @@ ${accountHTML}
<div class="b3-label">
${window.siyuan.languages.about2}
<div class="fn__hr"></div>
- <input class="b3-text-field fn__block" readonly value="http://${window.siyuan.config.system.networkServe ? window.siyuan.config.localIPs[0] : "127.0.0.1"}:${location.port}">
+ <input class="b3-text-field fn__block" readonly value="http://${window.siyuan.config.system.networkServe ? window.siyuan.config.localIPs[0] : "siyuan.localhost"}:${location.port}">
<div class="b3-label__text">${window.siyuan.languages.about3.replace("${port}", location.port)}</div>
<div class="fn__hr"></div>
<span class="b3-label__text"><code class="fn__code">${window.siyuan.config.localIPs.join("</code> <code class='fn__code'>")}</code></span>
diff --git a/app/stage/auth.html b/app/stage/auth.html
index 4d9ad1bfc9..62adca09a1 100644
--- a/app/stage/auth.html
+++ b/app/stage/auth.html
@@ -387,7 +387,7 @@
<div class="b3-snackbar__content"></div>
</div>
<script>
- if (location.hostname !== '127.0.0.1') {
+ if (location.hostname !== 'siyuan.localhost' && location.hostname !== '127.0.0.1') {
document.querySelector('.b3-button--white').remove()
}
diff --git a/kernel/api/export.go b/kernel/api/export.go
index 35e343b565..c5195d58ea 100644
--- a/kernel/api/export.go
+++ b/kernel/api/export.go
@@ -209,7 +209,7 @@ func exportTempContent(c *gin.Context) {
}
url := path.Join("/export/temp/", filepath.Base(p))
ret.Data = map[string]interface{}{
- "url": "http://127.0.0.1:" + util.ServerPort + url,
+ "url": "http://" + util.LocalHost + ":" + util.ServerPort + url,
}
}
@@ -229,7 +229,7 @@ func exportPreviewHTML(c *gin.Context) {
}
name, content := model.ExportHTML(id, "", true, keepFold)
// 导出 PDF 预览时点击块引转换后的脚注跳转不正确 https://github.com/siyuan-note/siyuan/issues/5894
- content = strings.ReplaceAll(content, "http://127.0.0.1:"+util.ServerPort+"/#", "#")
+ content = strings.ReplaceAll(content, "http://"+util.LocalHost+":"+util.ServerPort+"/#", "#")
ret.Data = map[string]interface{}{
"id": id,
diff --git a/kernel/model/export.go b/kernel/model/export.go
index 863a637d65..e39371ba2e 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -438,7 +438,7 @@ func ExportHTML(id, savePath string, pdf, keepFold bool) (name, dom string) {
}
}
} else { // 导出 PDF 需要将资源文件路径改为 HTTP 伺服
- luteEngine.RenderOptions.LinkBase = "http://127.0.0.1:" + util.ServerPort + "/"
+ luteEngine.RenderOptions.LinkBase = "http://" + util.LocalHost + ":" + util.ServerPort + "/"
}
if pdf {
diff --git a/kernel/model/session.go b/kernel/model/session.go
index c665478215..b82dd6c447 100644
--- a/kernel/model/session.go
+++ b/kernel/model/session.go
@@ -171,7 +171,7 @@ func CheckAuth(c *gin.Context) {
}
// 放过来自本机的某些请求
- if strings.HasPrefix(c.Request.RemoteAddr, "127.0.0.1") {
+ if strings.HasPrefix(c.Request.RemoteAddr, util.LocalHost) || strings.HasPrefix(c.Request.RemoteAddr, "127.0.0.1") {
if strings.HasPrefix(c.Request.RequestURI, "/assets/") || strings.HasPrefix(c.Request.RequestURI, "/history/assets/") {
c.Next()
return
diff --git a/kernel/util/path.go b/kernel/util/path.go
index 05cab8ca7c..f630f7a815 100644
--- a/kernel/util/path.go
+++ b/kernel/util/path.go
@@ -87,7 +87,7 @@ var LocalIPs []string
func GetLocalIPs() (ret []string) {
if ContainerAndroid == Container {
// Android 上用不了 net.InterfaceAddrs() https://github.com/golang/go/issues/40569,所以前面使用启动内核传入的参数 localIPs
- LocalIPs = append(LocalIPs, "127.0.0.1")
+ LocalIPs = append(LocalIPs, LocalHost)
LocalIPs = gulu.Str.RemoveDuplicatedElem(LocalIPs)
return LocalIPs
}
@@ -104,7 +104,7 @@ func GetLocalIPs() (ret []string) {
ret = append(ret, networkIp.IP.String())
}
}
- ret = append(ret, "127.0.0.1")
+ ret = append(ret, LocalHost)
ret = gulu.Str.RemoveDuplicatedElem(ret)
return
}
diff --git a/kernel/util/web.go b/kernel/util/web.go
index 77061df5d4..7fc757c2e5 100644
--- a/kernel/util/web.go
+++ b/kernel/util/web.go
@@ -17,9 +17,7 @@
package util
import (
- "net"
"strings"
- "time"
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
@@ -50,16 +48,3 @@ func JsonArg(c *gin.Context, result *gulu.Result) (arg map[string]interface{}, o
ok = true
return
}
-
-func isPortOpen(port string) bool {
- timeout := time.Second
- conn, err := net.DialTimeout("tcp", net.JoinHostPort("127.0.0.1", port), timeout)
- if nil != err {
- return false
- }
- if nil != conn {
- conn.Close()
- return true
- }
- return false
-}
diff --git a/kernel/util/working.go b/kernel/util/working.go
index da80ec383f..b4394e69ac 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -293,7 +293,8 @@ const (
ContainerAndroid = "android" // Android 端
ContainerIOS = "ios" // iOS 端
- FixedPort = "6806" // 固定端口
+ LocalHost = "siyuan.localhost" // 本地域名,由操作系统自动解析到 127.0.0.1
+ FixedPort = "6806" // 固定端口
)
func initPathDir() {