@@ -17,60 +17,42 @@ import com.nphausg.app.embeddedserver.data.Database
17
17
import com.nphausg.app.embeddedserver.data.models.Cart
18
18
import com.nphausg.app.embeddedserver.extensions.animateFlash
19
19
import com.nphausg.app.embeddedserver.utils.NetworkUtils
20
- import io.ktor.application.call
21
- import io.ktor.application.install
22
- import io.ktor.features.CORS
23
- import io.ktor.features.CallLogging
24
- import io.ktor.features.Compression
25
- import io.ktor.features.ContentNegotiation
26
- import io.ktor.features.gzip
27
- import io.ktor.gson.gson
20
+ import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
28
21
import io.ktor.http.ContentType
29
- import io.ktor.http.HttpMethod
30
22
import io.ktor.http.HttpStatusCode
31
- import io.ktor.response.respond
32
- import io.ktor.response.respondText
33
- import io.ktor.routing.get
34
- import io.ktor.routing.routing
23
+ import io.ktor.serialization.kotlinx.json.json
24
+ import io.ktor.server.application.call
25
+ import io.ktor.server.application.install
35
26
import io.ktor.server.engine.embeddedServer
36
27
import io.ktor.server.netty.Netty
37
- import io.ktor.websocket.WebSockets
28
+ import io.ktor.server.plugins.cors.routing.CORS
29
+ import io.ktor.server.response.respond
30
+ import io.ktor.server.response.respondText
31
+ import io.ktor.server.routing.get
32
+ import io.ktor.server.routing.routing
38
33
import kotlinx.coroutines.CoroutineScope
39
34
import kotlinx.coroutines.Dispatchers
40
35
import kotlinx.coroutines.launch
36
+ import kotlinx.serialization.json.Json
41
37
42
38
class MainActivity : AppCompatActivity () {
43
39
44
40
companion object {
45
- private const val PORT = 5001
41
+ private const val PORT = 6868
46
42
}
47
43
48
44
private val server by lazy {
49
45
embeddedServer(Netty , PORT , watchPaths = emptyList()) {
50
- install(WebSockets )
51
- install(CallLogging )
52
- // provides the automatic content conversion of requests based on theirContent-Type
53
- // and Accept headers. Together with the json() setting, this enables automatic
54
- // serialization and deserialization to and from JSON – allowing
55
- // us to delegate this tedious task to the framework.
56
- install(ContentNegotiation ) {
57
- gson {
58
- setPrettyPrinting()
59
- disableHtmlEscaping()
60
- }
61
- }
62
46
// configures Cross-Origin Resource Sharing. CORS is needed to make calls from arbitrary
63
47
// JavaScript clients, and helps us prevent issues down the line.
64
48
install(CORS ) {
65
- method(HttpMethod .Get )
66
- method(HttpMethod .Post )
67
- method(HttpMethod .Delete )
68
49
anyHost()
69
50
}
70
- // Greatly reduces the amount of data that's needed to be sent to the client by
71
- // gzipping outgoing content when applicable.
72
- install(Compression ) {
73
- gzip()
51
+ install(ContentNegotiation ) {
52
+ json(Json {
53
+ prettyPrint = true
54
+ isLenient = true
55
+ })
74
56
}
75
57
routing {
76
58
get(" /" ) {
0 commit comments