override fun process()

in dsl/kotless/kotless-lang-parser/src/main/kotlin/io/kotless/parser/processor/route/StaticRoutesProcessor.kt [25:53]


    override fun process(files: Set<KtFile>, binding: BindingContext, context: ProcessorContext) {
        processStaticVariables(files, binding) { variable, entry, _ ->
            val path = entry.getURIPath(binding, StaticGet::path)
                ?: error(variable, "For @StaticGet annotation `path` parameter is required")
            val mime = entry.getEnumValue(binding, StaticGet::mime)
                ?: error(variable, "For @StaticGet annotation `path` parameter is required")

            require(variable, variable.getTypeFqName(binding).toString() == File::class.qualifiedName) {
                "Variable annotated with @StaticGet should have type java.io.File"
            }
            require(variable, variable.initializer is KtCallExpression) {
                "Variable annotated with @StaticGet should be created via File(\"...\") constructor"
            }

            val arguments = (variable.initializer as KtCallExpression).valueArguments

            require(variable, arguments.size == 1) {
                "Variable annotated with @StaticGet should be created via File(\"...\") constructor with one argument"
            }

            val file = File(context.config.dsl.staticsRoot, arguments.single().text.trim('"'))

            val key = TypedStorage.Key<StaticResource>()
            val resource = StaticResource(URIPath("static", path), file, mime)

            context.resources.register(key, resource)
            context.routes.register(Application.API.StaticRoute(path, key))
        }
    }