https support

This commit is contained in:
liteng 2021-03-28 17:09:53 +08:00
parent c14c4994f3
commit 8222ae1721
10 changed files with 97 additions and 6 deletions

View File

@ -26,6 +26,7 @@ English / [中文](README_zh.md) &nbsp;&nbsp; | &nbsp;&nbsp; <a href="https://gi
2. Check VR in the status bar to enable VR.
3. Set scene transform.
4. How to popup a window when click an object: https://gitee.com/tengge1/ShadowEditor/issues/I3APGI
5. You can enable `https` in the `config.toml`.
## v0.5.10 has Released
@ -160,7 +161,8 @@ git clone https://gitee.com/tengge1/ShadowEditor.git
2. Run `npm install` to install nodejs dependencies.
3. Run `npm run build` to build the server and web.
4. Edit `build/config.toml`, and modify the mongodb host and port.
5. Run `npm run start` to launch the server. You can now visit: `http://localhost:2020`.
5. Run `npm start` to launch the server. You can now visit: `http://localhost:2020`.
6. If you enable `https` in the config file. Please visit: `https://localhost:2020`.
**Desktop Version:**
@ -289,6 +291,18 @@ The data structure and web client is not changed, just copy `./ShadowEditor.Web/
Windows requires `Visual C++ Redistributable for Visual Studio 2015`. You can install from: https://www.microsoft.com/en-us/download/details.aspx?id=48145
If the desktop version cannot be opened, you can view `logs.txt`; if the port conflicts, you can modify the MongoDB and website ports in `resources/app/config.toml`.
7. How can I create a https certificate?
Install `openssl`, and git client already contains one; Open `cmd`, `Powershell` or `shell`, and run the following commands:
```sh
openssl genrsa -out privatekey.pem 1024
openssl req -new -key privatekey.pem -out certrequest.csr
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
```
Among the generated files, `certificate.pem` is the certificate, and `privatekey.pem` is the key.
</details>
## License

View File

@ -26,6 +26,7 @@
2. 状态栏勾选虚拟现实启用VR功能。
3. 设置场景位移。
4. 点击物体时怎么弹出窗口https://gitee.com/tengge1/ShadowEditor/issues/I3APGI
5. 你可以在`config.toml`中启用`https`
## v0.5.10已经发布
@ -160,7 +161,8 @@ git clone https://gitee.com/tengge1/ShadowEditor.git
2. 执行`npm install`安装nodejs依赖。
3. 执行`npm run build`构建服务端和Web端。
4. 编辑`build/config.toml`修改MongoDB的host和port设置。
5. 执行`npm run start`启动服务端。现在你可以访问:`http://localhost:2020`
5. 执行`npm start`启动服务端。现在你可以访问:`http://localhost:2020`
6. 如果在配置文件中启用了`https`,请访问:`https://localhost:2020`
**桌面版:**
@ -285,6 +287,18 @@ ShadowEditor是一个为用户和开发者而生的项目。在这个项目上
说明Windows需要`Visual C++ Redistributable for Visual Studio 2015`。你可以从这安装https://www.microsoft.com/en-us/download/details.aspx?id=48145
说明:如果桌面版打不开,可以查看`logs.txt`;如果端口冲突,可以修改`resources/app/config.toml`中的MongoDB和网站端口。
7. 如何创建一个https证书
安装`openssl`git客户端已经自带一个。打开`cmd``Powershell``shell`,运行以下命令:
```sh
openssl genrsa -out privatekey.pem 1024
openssl req -new -key privatekey.pem -out certrequest.csr
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
```
在生成的文件中,`certificate.pem`是证书,`privatekey.pem`是密钥。
</details>
## 开源项目

View File

@ -49,6 +49,8 @@ async function main() {
}
console.log('copy config.toml to the build directory');
fs.copyFileSync('config.toml', '../build/config.toml');
console.log('copy certificate to the build directory');
fs.copySync('../utils/certificate/', '../build/certificate/');
console.log(`leave ${serverDir}`);
process.chdir(rootDir);

View File

@ -2,6 +2,9 @@
[server]
port = ":2020" # server address
https = false # whether enable https
certPath = "./certificate/certificate.pem" # The certificate path
keyPath = "./certificate/privatekey.pem" # The key path
[database]
type = "mongo" # only support mongo

View File

@ -2,6 +2,9 @@
[server]
port = ":2020" # server address
https = false # whether enable https
certPath = "./certificate/certificate.pem" # The certificate path
keyPath = "./certificate/privatekey.pem" # The key path
[database]
type = "mongo" # only support mongo

View File

@ -70,7 +70,10 @@ type ConfigModel struct {
// ServerConfigModel is the server config section in `config.toml`.
type ServerConfigModel struct {
Port string `toml:"port"`
Port string `toml:"port"`
HttpsEnabled bool `toml:"https"`
CertPath string `toml:"certPath"`
KeyPath string `toml:"keyPath"`
}
// DatabaseConfigModel is the database config section in `config.toml`.

View File

@ -77,9 +77,17 @@ func Start() {
close(idleConnsClosed)
}()
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
// Error starting or closing listener:
log.Printf("HTTP server ListenAndServe: %v", err)
if Config.Server.HttpsEnabled {
certPath, keyPath := Config.Server.CertPath, Config.Server.KeyPath
if err := srv.ListenAndServeTLS(certPath, keyPath); err != http.ErrServerClosed {
// Error starting or closing listener:
log.Printf("HTTPS server ListenAndServe: %v", err)
}
} else {
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
// Error starting or closing listener:
log.Printf("HTTP server ListenAndServe: %v", err)
}
}
<-idleConnsClosed

View File

@ -0,0 +1,16 @@
-----BEGIN CERTIFICATE-----
MIICjjCCAfcCFD+soSvUIKp16dd8lnw9n1wmZMTwMA0GCSqGSIb3DQEBCwUAMIGF
MQswCQYDVQQGEwJDTjERMA8GA1UECAwIU2hhbmRvbmcxDTALBgNVBAcMBFppYm8x
ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEQMA4GA1UEAwwHdGVu
Z2dlMTEfMB0GCSqGSIb3DQEJARYQOTMwMzcyNTUxQHFxLmNvbTAeFw0yMTAzMjgw
ODUxMzJaFw0yMTA0MjcwODUxMzJaMIGFMQswCQYDVQQGEwJDTjERMA8GA1UECAwI
U2hhbmRvbmcxDTALBgNVBAcMBFppYm8xITAfBgNVBAoMGEludGVybmV0IFdpZGdp
dHMgUHR5IEx0ZDEQMA4GA1UEAwwHdGVuZ2dlMTEfMB0GCSqGSIb3DQEJARYQOTMw
MzcyNTUxQHFxLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwazDEA0H
C5M2NL9sRiOzuGsUu2VwpOd0A7r9Bjhw94syUvlfccNH+ctKEZOe5jlBbO+c1XpU
zhYcU/4EfvMWe9/J+m4rBLDkCczgYpAF/1fvYSanyY94hJ0Lm/UTgg6EkExofO/+
wIJfJ3qmiCLksC7eRnDVEgddbdx0SOFIw9ECAwEAATANBgkqhkiG9w0BAQsFAAOB
gQBbwCsBjrSZRzfyR+dkY1iHi+wMLnJvort39l9VDThZAspIclwmNDG8/Fc3x9Nr
WsUsG0i86QcwfsR5usoKG8qXus2Gc/NrH+Tx+GuqYZ08B0gz5LAQf7Lil/a0db+/
ltKhEJ7evIuAG5304HP7gTVX3HlrxquIE6OgDzqCuTnqvA==
-----END CERTIFICATE-----

View File

@ -0,0 +1,13 @@
-----BEGIN CERTIFICATE REQUEST-----
MIIB3TCCAUYCAQAwgYUxCzAJBgNVBAYTAkNOMREwDwYDVQQIDAhTaGFuZG9uZzEN
MAsGA1UEBwwEWmlibzEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRk
MRAwDgYDVQQDDAd0ZW5nZ2UxMR8wHQYJKoZIhvcNAQkBFhA5MzAzNzI1NTFAcXEu
Y29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBrMMQDQcLkzY0v2xGI7O4
axS7ZXCk53QDuv0GOHD3izJS+V9xw0f5y0oRk57mOUFs75zVelTOFhxT/gR+8xZ7
38n6bisEsOQJzOBikAX/V+9hJqfJj3iEnQub9ROCDoSQTGh87/7Agl8neqaIIuSw
Lt5GcNUSB11t3HRI4UjD0QIDAQABoBcwFQYJKoZIhvcNAQkHMQgMBjEyMzQ1NjAN
BgkqhkiG9w0BAQsFAAOBgQCCr0FqS+3P4EWBXQN2bFXQzB79gbyzG9jbHY5P7sMu
eIW9B2ZKIdaYPQtwdJcOKmUvUih//DmovPWtSQp0b9iDNmAnLtVvVU3Src52K8Tj
4c4Fik6q3JAsz+KRhVwcQKxgHVWbOIoxyXZsewxfSfEOIUw+TWHym0hWIPu5sdUQ
+Q==
-----END CERTIFICATE REQUEST-----

View File

@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDBrMMQDQcLkzY0v2xGI7O4axS7ZXCk53QDuv0GOHD3izJS+V9x
w0f5y0oRk57mOUFs75z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