diff --git a/numass-web-control/.gitignore b/numass-web-control/.gitignore new file mode 100644 index 00000000..b63da455 --- /dev/null +++ b/numass-web-control/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/numass-web-control/build.gradle.kts b/numass-web-control/build.gradle.kts new file mode 100644 index 00000000..38079d2f --- /dev/null +++ b/numass-web-control/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + application +} + +group = "inr.numass" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") + implementation("io.ktor:ktor-server-core:2.3.7") + implementation("io.ktor:ktor-server-netty:2.3.7") + +} + +tasks.test { + useJUnitPlatform() +} + +application { + mainClass.set("inr.numass.webcontrol.ServerKt") +} \ No newline at end of file diff --git a/numass-web-control/src/main/java/inr/numass/webcontrol/Server.kt b/numass-web-control/src/main/java/inr/numass/webcontrol/Server.kt new file mode 100644 index 00000000..64fb20d6 --- /dev/null +++ b/numass-web-control/src/main/java/inr/numass/webcontrol/Server.kt @@ -0,0 +1,26 @@ +package inr.numass.webcontrol + +import io.ktor.server.routing.* +import io.ktor.http.* +import io.ktor.server.application.* +import io.ktor.server.response.* +import io.ktor.server.request.* +import io.ktor.server.engine.* +import io.ktor.server.netty.* +import java.nio.file.Paths +import io.ktor.server.http.content.* +fun main() { + var clickNumber = 0 + embeddedServer(Netty, port = 8000) { + + routing { + staticFiles("/", Paths.get(this.javaClass.classLoader.getResource("index.html").toURI()).toFile().parentFile) + get ("/api") { + call.respondText(call.parameters.toString()) + } + get ("/api/clicker") { + call.respondText(clickNumber++.toString()) + } + } + }.start(wait = true) +} \ No newline at end of file diff --git a/numass-web-control/src/main/resources/index.html b/numass-web-control/src/main/resources/index.html new file mode 100644 index 00000000..fbc62cf8 --- /dev/null +++ b/numass-web-control/src/main/resources/index.html @@ -0,0 +1,44 @@ + + +
+ +