fix CLI boostrap of http server
This commit is contained in:
parent
2dc4fb8230
commit
fae9965bdf
14
docs/ai_notes_cli_release.md
Normal file
14
docs/ai_notes_cli_release.md
Normal file
@ -0,0 +1,14 @@
|
||||
# AI notes: publish JVM CLI updates with `bin/local_jrelease`
|
||||
|
||||
[//]: # (excludeFromIndex)
|
||||
|
||||
When a change affects the JVM CLI launcher used as `jlyng`, refresh the installed local distribution with:
|
||||
|
||||
```bash
|
||||
bin/local_jrelease
|
||||
```
|
||||
|
||||
Why:
|
||||
- `jlyng` in this repo is installed from `~/bin/jlyng-jvm/lyng-jvm`, not directly from `lyng/build/install`.
|
||||
- Manual copying from Gradle build output can leave the actual launcher on `PATH` stale.
|
||||
- `bin/local_jrelease` rebuilds `lyng/build/distributions/lyng-jvm.zip`, reinstalls it under `~/bin/jlyng-jvm`, and recreates the `~/bin/jlyng` symlink.
|
||||
@ -90,6 +90,7 @@ Requires installing `lyngio` into the import manager from host code.
|
||||
- `import lyng.io.process` (process execution API)
|
||||
- `import lyng.io.console` (console capabilities, geometry, ANSI/output, events)
|
||||
- `import lyng.io.http` (HTTP/HTTPS client API)
|
||||
- `import lyng.io.http.server` (minimal HTTP/1.1 and WebSocket server API)
|
||||
- `import lyng.io.ws` (WebSocket client API; currently supported on JVM, capability-gated elsewhere)
|
||||
- `import lyng.io.net` (TCP/UDP transport API; currently supported on JVM, capability-gated elsewhere)
|
||||
- Shared network value-type packages are also available when installed by host code:
|
||||
|
||||
19
examples/http_server.lyng
Normal file
19
examples/http_server.lyng
Normal file
@ -0,0 +1,19 @@
|
||||
import lyng.io.http.server
|
||||
|
||||
closed class CreateUserRequest(name: String, age: Int)
|
||||
closed class CreateUserResponse(id: Int, name: String, age: Int)
|
||||
|
||||
val server = HttpServer()
|
||||
|
||||
server.postPath("/api/users") {
|
||||
val req = jsonBody<CreateUserRequest>()
|
||||
|
||||
if (req.name.isBlank()) {
|
||||
respondJson({ error: "name must not be empty" }, 400)
|
||||
return
|
||||
}
|
||||
|
||||
respondJson(CreateUserResponse(101, req.name, req.age), 201)
|
||||
}
|
||||
|
||||
server.listen(8080, "127.0.0.1")
|
||||
@ -17,8 +17,8 @@
|
||||
|
||||
package net.sergeych
|
||||
|
||||
import com.github.ajalt.clikt.core.CoreCliktCommand
|
||||
import com.github.ajalt.clikt.core.Context
|
||||
import com.github.ajalt.clikt.core.CoreCliktCommand
|
||||
import com.github.ajalt.clikt.core.main
|
||||
import com.github.ajalt.clikt.core.subcommands
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
@ -46,15 +46,16 @@ import net.sergeych.lyng.io.db.jdbc.createJdbcModule
|
||||
import net.sergeych.lyng.io.db.sqlite.createSqliteModule
|
||||
import net.sergeych.lyng.io.fs.createFs
|
||||
import net.sergeych.lyng.io.http.createHttpModule
|
||||
import net.sergeych.lyng.io.http.server.createHttpServerModule
|
||||
import net.sergeych.lyng.io.net.createNetModule
|
||||
import net.sergeych.lyng.io.ws.createWsModule
|
||||
import net.sergeych.lyng.obj.*
|
||||
import net.sergeych.lyng.pacman.ImportManager
|
||||
import net.sergeych.lyngio.net.shutdownSystemNetEngine
|
||||
import net.sergeych.lyngio.console.security.PermitAllConsoleAccessPolicy
|
||||
import net.sergeych.lyngio.fs.security.PermitAllAccessPolicy
|
||||
import net.sergeych.lyngio.http.security.PermitAllHttpAccessPolicy
|
||||
import net.sergeych.lyngio.net.security.PermitAllNetAccessPolicy
|
||||
import net.sergeych.lyngio.net.shutdownSystemNetEngine
|
||||
import net.sergeych.lyngio.ws.security.PermitAllWsAccessPolicy
|
||||
import net.sergeych.mp_tools.globalDefer
|
||||
import okio.*
|
||||
@ -146,6 +147,7 @@ private fun ImportManager.invalidateCliModuleCaches() {
|
||||
invalidatePackageCache("lyng.io.db.jdbc")
|
||||
invalidatePackageCache("lyng.io.db.sqlite")
|
||||
invalidatePackageCache("lyng.io.http")
|
||||
invalidatePackageCache("lyng.io.http.server")
|
||||
invalidatePackageCache("lyng.io.ws")
|
||||
invalidatePackageCache("lyng.io.net")
|
||||
}
|
||||
@ -236,6 +238,7 @@ private fun installCliModules(manager: ImportManager) {
|
||||
createJdbcModule(manager)
|
||||
createSqliteModule(manager)
|
||||
createHttpModule(PermitAllHttpAccessPolicy, manager)
|
||||
createHttpServerModule(PermitAllNetAccessPolicy, manager)
|
||||
createWsModule(PermitAllWsAccessPolicy, manager)
|
||||
createNetModule(PermitAllNetAccessPolicy, manager)
|
||||
}
|
||||
|
||||
@ -73,10 +73,12 @@ class CliNetworkJvmTest {
|
||||
try {
|
||||
val script = """
|
||||
import lyng.io.http
|
||||
import lyng.io.http.server
|
||||
import lyng.io.ws
|
||||
import lyng.io.net
|
||||
|
||||
assert(Http.isSupported())
|
||||
assert(HttpServer() is HttpServer)
|
||||
println("ws=" + Ws.isSupported())
|
||||
println("net=" + Net.isSupported())
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user