Skip to content

Commit b6dffc2

Browse files
committed
Serve skiko on the server
1 parent 6abd1a1 commit b6dffc2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.gradle.kotlin.dsl.support.serviceOf
12
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
23
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
34
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -53,6 +54,11 @@ allprojects {
5354
}
5455
}
5556

57+
val resourceDependency: Configuration by configurations.creating {
58+
isCanBeResolved = true
59+
isCanBeConsumed = false
60+
}
61+
5662
dependencies {
5763
annotationProcessor("org.springframework:spring-context-indexer")
5864
implementation("com.google.code.gson:gson")
@@ -79,6 +85,8 @@ dependencies {
7985
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
8086
}
8187
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
88+
89+
resourceDependency("org.jetbrains.skiko:skiko-js-wasm-runtime:0.7.90")
8290
}
8391

8492
fun buildPropertyFile() {
@@ -156,6 +164,15 @@ val buildLambda by tasks.creating(Zip::class) {
156164
}
157165
}
158166

167+
tasks.named<Copy>("processResources") {
168+
val archiveOperation = project.serviceOf<ArchiveOperations>()
169+
from(resourceDependency.map {
170+
archiveOperation.zipTree(it)
171+
}) {
172+
into("com/compiler/server")
173+
}
174+
}
175+
159176
tasks.withType<Test> {
160177
dependsOn(rootProject.the<NodeJsRootExtension>().nodeJsSetupTaskProvider)
161178
useJUnitPlatform()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.compiler.server.controllers
2+
3+
import org.springframework.core.io.FileSystemResource
4+
import org.springframework.core.io.Resource
5+
import org.springframework.http.*
6+
import org.springframework.web.bind.annotation.GetMapping
7+
import org.springframework.web.bind.annotation.RequestMapping
8+
import org.springframework.web.bind.annotation.RestController
9+
import java.util.concurrent.TimeUnit
10+
11+
12+
@RestController
13+
@RequestMapping(value = ["/api/resource", "/api/**/resource"])
14+
class ResourceRestController {
15+
@GetMapping("/skiko.mjs")
16+
fun getSkikoMjs(): ResponseEntity<Resource> {
17+
return cacheableResource("/com/compiler/server/skiko.mjs", MediaType("text", "javascript"))
18+
}
19+
20+
@GetMapping("/skiko.wasm")
21+
fun getSkikoWasm(): ResponseEntity<Resource> {
22+
return cacheableResource("/com/compiler/server/skiko.wasm", MediaType("application", "wasm"))
23+
}
24+
25+
private fun cacheableResource(path: String, mediaType: MediaType): ResponseEntity<Resource> {
26+
val resourcePath = javaClass.getResource(path)?.path
27+
?: return ResponseEntity.internalServerError().build()
28+
29+
val resource = FileSystemResource(resourcePath)
30+
val headers = HttpHeaders().apply {
31+
contentType = mediaType
32+
cacheControl = CacheControl.maxAge(365, TimeUnit.DAYS).headerValue
33+
}
34+
35+
return ResponseEntity(resource, headers, HttpStatus.OK)
36+
}
37+
}

0 commit comments

Comments
 (0)