Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sanyavertolet/statics
Serve static resources on JVM and native
https://github.com/sanyavertolet/statics
kotlin kotlin-jvm kotlin-multiplatform kotlin-native ktor ktor-server static-resources
Last synced: 8 days ago
JSON representation
Serve static resources on JVM and native
- Host: GitHub
- URL: https://github.com/sanyavertolet/statics
- Owner: sanyavertolet
- License: mit
- Created: 2024-06-28T14:09:46.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-10-28T17:12:00.000Z (2 months ago)
- Last Synced: 2024-11-06T20:50:22.663Z (about 2 months ago)
- Topics: kotlin, kotlin-jvm, kotlin-multiplatform, kotlin-native, ktor, ktor-server, static-resources
- Language: Kotlin
- Homepage: https://sanyavertolet.github.io/statics/
- Size: 371 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Module ktor-statics
This project is a tiny library for `Ktor`-based apps designed to serve static files such as HTML, JavaScript, and CSS.
The problem is that Ktor has `staticResources()` on `jvm`, while `native` does not have any easy mechanism to configure serving static files.`Ktor-statics` provides a function available on `jvm`, `linuxX64`, `linuxArm64`, `macosX64`, and `macosArm64` targets:
```kotlin
statics(remotePath = "/", basePackage = "path/to/resource/folder", index = "index.html")
```* `remotePath` - prefix for `statics` requests;
* `basePackage` - path to `statics` (on `jvm` - path to resources inside your `.jar`, on `native` - path to folder);
* `index` - file that should be served if no path matches.#### On `jvm`, `statics` uses `staticResources` under the hood. If you want same behaviour on `jvm`, use `alternativeStatics`.
## Installation and Usage
1. Add GitHub maven repository to your `settings.gradle.kts` file:
```kotlin
dependencyResolutionManagement {
repositories {
mavenCentral()
maven {
name = "sanyavertolet/statics"
url = uri("https://maven.pkg.github.com/sanyavertolet/statics")
credentials {
username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR")
password = providers.gradleProperty("gpr.key").orNull ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
```
For more information, read [GitHub Docs](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry).2. Add `com.sanyavertolet.statics:ktor-statics:{STATICS_VERSION}` to dependencies in your `build.gradle.kts` file:
```kotlin
kotlin {
jvm()
linuxX64()
sourceSets {
commonMain {
dependencies {
// other dependencies
implementation("com.sanyavertolet.statics:ktor-statics:${STATICS_VERSION}")
}
}
}
}
```3. Use `statics` in your routing configuration:
```kotlin
// jvm
fun Application.module() {
// some other configurations
routing {
// other routing configuration
statics("/", "public")
}
}// native
fun Application.module() {
// some other configurations
routing {
// other routing configuration
statics("/", "/path/to/public")
}
}
```## Contributing
All the contributions are welcomed!
Please see [CONTRIBUTING.md](CONTRIBUTING.md) file for details on how to get started.## Support
For support or to report bugs, please open an issue on [statics issues](https://github.com/sanyavertolet/statics/issues) page.## License
`statics` is licensed under the `MIT Licence`.
See the [LICENSE](LICENSE) file for details.