Hackers at Cambridge Website
The public website of Hackers at Cambridge
This website is built using the Swift web framework Kitura. This allows us to build the site fast and reliably and to learn about and contribute to server-side Swift in the process.
Installing and running the website
We use Docker to make installation quick and painless, make sure you have it installed. This has been tested to work with at least
docker 17.03.0-ce, build 60ccb22 and
docker-compose version 1.11.2, build dfed245.
If you are on Windows, go to docker settings and ensure the drive you are using is shared.
- Clone this repository:
git clone https://github.com/hackersatcambridge/hac-website.git
- Navigate to the hac-website directory that you've now cloned
- Create an empty file named
.env, add the key-value pairs described below, and save it*
- Now run
This will build the project run the web server at
localhost:3000. It will also watch for changes to the files and rebuild as necessarily. You can stop this process at any time with
When you want to run the project again (and you will, it's great):
- If the Dockerfile has been changed, run
*Why did we have to do that? The
.env file is used to store sensitive information like API keys and environment-specific information in here for our server to use. We load it with dummy or alternative data locally.
Please look at the CONTRIBUTING.md on how to contribute to the project!
.env file should contain the following items in the format: key="value"
| Key | Value Example | | - | - | | DATABASE_URL | postgres://richard:test@hac-db:5432/hac |
"Um. It looks like your HTML is written in Swift."
You may notice that we aren't using a templating library for rendering HTML. Inspired by the likes of Elm and React, we've written a module HaCTML for making HTML type-safe and Swifty! For an example, have a look at our home page.
We're currently experimenting with the API for HaCTML, and once it's a little more stable we hope to release it as a standalone module.
In order to run unit tests:
docker-compose run web yarn test
Working with the Docker container
docker-compose up is doing
This command starts up a docker container that has all the required dependencies, then starts up a development server.
- Builds the Swift files
- Builds the stylesheets
- Starts the server (at
- Waits eagerly for you to make changes to any of the files, rebuilds, and reloads the browser (powered by BrowserSync)
*It is worth noting that we are using Gulp v4, which hasn't been officially released. It would be useful to refer to the version 4 documentation.
Running commands in the container
If you want to access an instance of
swift inside the Docker container to do some debugging or modifications, you can simply use
docker-compose run web swift <<SWIFT COMMAND>> docker-compose run web yarn <<YARN COMMAND>> docker-compose run web yarn gulp <<GULP COMMAND>>
As the container shares source files with your project directory, any source files modified inside the container (e.g.
package.json) will also be modified outside the container (and vice versa).