Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
c21b50c8
Commit
c21b50c8
authored
Feb 15, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
4e046c71
bcf6a2a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
10 deletions
+12
-10
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
...ain/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
+12
-10
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MiraiHttpAPIServer.kt
View file @
c21b50c8
...
...
@@ -15,15 +15,18 @@ import io.ktor.server.engine.applicationEngineEnvironment
import
io.ktor.server.engine.connector
import
io.ktor.server.engine.embeddedServer
import
io.ktor.util.KtorExperimentalAPI
import
kotlinx.coroutines.CoroutineExceptionHandler
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.launch
import
net.mamoe.mirai.api.http.route.mirai
import
net.mamoe.mirai.utils.DefaultLogger
import
org.slf4j.LoggerFactory
import
org.slf4j.helpers.NOPLogger
import
org.slf4j.helpers.NOPLoggerFactory
import
kotlin.coroutines.CoroutineContext
object
MiraiHttpAPIServer
{
object
MiraiHttpAPIServer
:
CoroutineScope
{
private
val
logger
=
DefaultLogger
(
"Mirai HTTP API"
)
override
val
coroutineContext
:
CoroutineContext
=
CoroutineExceptionHandler
{
_
,
throwable
->
logger
.
error
(
throwable
)
}
init
{
SessionManager
.
authKey
=
generateSessionKey
()
//用于验证的key, 使用和SessionKey相同的方法生成, 但意义不同
...
...
@@ -43,20 +46,19 @@ object MiraiHttpAPIServer {
SessionManager
.
authKey
=
authKey
// TODO: start是无阻塞的,理应获取启动状态后再执行后续代码
try
{
launch
{
embeddedServer
(
CIO
,
environment
=
applicationEngineEnvironment
{
this
.
parentCoroutineContext
=
coroutineContext
this
.
log
=
NOPLoggerFactory
().
getLogger
(
"NMYSL"
)
this
.
module
(
Application
::
mirai
)
connector
{
this
.
port
=
port
}
}).
start
()
logger
.
info
(
"Http api server is running with authKey: ${SessionManager.authKey}"
)
callback
?.
invoke
()
}
catch
(
e
:
Exception
)
{
logger
.
error
(
"Http api server launch error"
)
}).
start
(
wait
=
true
)
}
logger
.
info
(
"Http api server is running with authKey: ${SessionManager.authKey}"
)
callback
?.
invoke
()
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment