Skip to content

modswift/mod_swift

Repository files navigation

mod_swift

Apache 2 Swift macOS tuxOS

mod_swift allows you to write native modules for the Apache Web Server in the Swift programming language. Server Side Swift the right way.

This project/sourcedir contains the actual C-language mod_swift. It is a straight Apache module which is then used to load Swift based Apache modules (mods_xyz).

Also included are Xcode base configurations, module maps for Apache and APR as well as a few API wrappers that are used to workaround swiftc crashers and Swift-C binding limitations.

Note: mod_swift is very low level, we currently provide two efforts to make Apache module development more pleasant: the Swift Apache API, and ApacheExpress. The latter provides a very convenient Node.js/ExpressJS like API which makes it very easy to write modules.

Documentation

You can find pretty neat mod_swift documentation over here: docs.mod-swift.org.

Status

  • 2022-05-08:
    • Updated for macOS 12 M1 Homebrew. Back in a working state!
    • Note that Homebrew APRUtil only comes w/ the SQLite driver. To use other drivers with mod_dbd, a manual install is necessary.
  • 2017-06-12:
    • This is not a demo anymore, it actually seems to work quite well.

Quick Install

$ brew tap modswift/mod_swift
$ brew install httpd mod_swift

$ swift apache validate
swift-driver version: 1.45.2 The Swift Apache build environment looks sound.

  srcroot:   /Users/helge/tmp/mods_helloworld
  module:    mods_helloworld
  config:    debug
  product:   /Users/helge/tmp/mods_helloworld/.build/mods_helloworld.so
  apxs:      /opt/homebrew/bin/apxs
  moddir:    /opt/homebrew/lib/httpd/modules
  relmoddir: /
  mod_swift: /opt/homebrew/opt/mod_swift
  swift:     5.6.0
  cert:      self-signed-mod_swift-localhost-server.crt
  http/2:    yes

HelloWorld Apache Module

$ mkdir mods_helloworld && cd mods_helloworld
$ swift apache init
The Swift Apache build environment looks sound.

  module:    mods_helloworld
  config:    debug
  product:   /Users/helge/tmp/tests/mods_helloworld/.build/mods_helloworld.so
  apxs:      /usr/local/bin/apxs
  mod_swift: /usr/local/opt/mod_swift
$ swift apache build
Fetching https://github.com/modswift/Apache.git
Fetching https://github.com/modswift/CApache.git
Completed resolution in 3.65s
Cloning https://github.com/modswift/CApache.git
Resolving https://github.com/modswift/CApache.git at 2.0.1
Cloning https://github.com/modswift/Apache.git
Resolving https://github.com/modswift/Apache.git at 0.5.0
[2/2] Compiling Swift Module 'mods_helloworld' (1 sources)

$ ls -hl .build/mods_helloworld.so
-rwxr-xr-x  1 helge  staff   173K 12 Mai 15:29 .build/mods_helloworld.so
$ swift apache serve
Note: DocRoot /usr/local/var/www/htdocs
Starting Apache on port 8042/8442:
GET /helloworld/ 200 715 - 0ms

Who

mod_swift is brought to you by ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.

There is a #mod_swift channel on the Noze.io Slack.

Want to support my work? Buy an app: Past for iChat, SVG Shaper, Shrugs, HMScriptEditor. You don't have to use it! 😀