Skip to content

Commit

Permalink
refactor(AnkiServer): make localhost a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Dec 14, 2023
1 parent b4db9f8 commit 54475d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/ReviewerServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ReviewerServer(activity: AbstractFlashcardViewer, private val mediaDir: St

override fun start() {
super.start()
Timber.i("Starting server on http://127.0.0.1:$listeningPort")
Timber.i("Starting server on http://$LOCALHOST:$listeningPort")
}

override fun serve(session: IHTTPSession): Response {
Expand Down
6 changes: 4 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/pages/AnkiServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ private const val PORT = 0

open class AnkiServer(
val activity: FragmentActivity
) : NanoHTTPD("127.0.0.1", PORT) {
) : NanoHTTPD(LOCALHOST, PORT) {

fun baseUrl(): String {
return "http://127.0.0.1:$listeningPort/"
return "http://$LOCALHOST:$listeningPort/"
}

override fun serve(session: IHTTPSession): Response {
Expand Down Expand Up @@ -119,6 +119,8 @@ open class AnkiServer(
}

companion object {
const val LOCALHOST = "127.0.0.1"

/** Common prefix used on Anki requests */
const val ANKI_PREFIX = "/_anki/"
const val ANKIDROID_JS_PREFIX = "/jsapi/"
Expand Down

0 comments on commit 54475d9

Please sign in to comment.