enoent.fr

Ktor: Altering served content

When serving files with Ktor, there might be times when you need to alter those files. For example, you might want to inject a script in every served HTML file. For this purpose, we can leverage plugins. Plugins can hook at different stages of the request/response pipeline: Ktor request/response pipeline Let’s write a plugin that transforms a specific type of files - going with the previous example of injecting a script to every served HTML file.

Read More…

Posted on

Serving static files with Ktor

Serving static files with Ktor for a static website seems easy enough: fun main() { embeddedServer(Netty, port = 8080) { routing { static { files("static-data") } } }.start(wait = true) } Done? Not quite. Opening http://localhost:8080 will only get you a 404, even if you have an index.html file in the static-data folder. You have to let Ktor know you want to opt-in serving a default file. Let’s try again (omitting anything outside the static block):

Read More…

Posted on

Hosting different kinds of apps on nginx

Engine what? Nginx (engine-x) is a web server and reverse proxy for web and mail protocols (HTTP, HTTPS, SMTP, POP3 and IMAP). It has been first released in 2004, and its usage keeps growing ever since (according to Netcraft, it was hosting 14.47% of active sites in August 2014). It’s capable of hosting many kinds of applications: static HTML pages PHP, using PHP-FPM Ruby on Rails and any kind of Rack-based Ruby application, using Phusion Passenger proxying requests to another webserver (e.g. a software launching its own web server, like Kodi)

Read More…

Posted on