• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    Clojure
  • Created about 4 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A web and API server, powered by xtdb.com
Important
This is the repository for Site 1.0. If you are looking for the latest version (Site 2.0), it is at https://github.com/juxt-site/site.

Site

CircleCI

Site is a project from JUXT to build a Resource Server out of our open-source XTDB database.

Site supports web content, and OpenAPI. You can use Site as a versioned Content Management System.

An official (work in progress) documentation website can be found here.

Note
A new version of Site is being developed here: https://github.com/juxt-site/site

What is Site?

Site is a Resource Server, built on the XTDB database.

You can put things into Site with (HTTP) PUT requests. When you do this, Site will put (the representation of) your thing (document, image, video, data…) into the database. You can get these later with a (HTTP) GET request with the same URI. In this way, Site behaves like a web server, with an immutable bitemporal content store.

APIs

If you PUT a JSON document with a Content-Type of application/vnd.oai.openapi+json;version=3.0.2, Site will treat this as an OpenAPI API definition, and serve that API for you. This OpenAPI API definition will contain the API endpoints, and provide schemas for the data transferred by the API. This tells the server how to validate data coming in to the API, and how to construct data on the way out.

APIs served from Site are good web citizens. They implement HTTP method semantics properly, with support for content negotiation, conditional requests, range requests and authentication.

APIs are also able to benefit from Site’s authorization module, Pass, providing Policy-Based Access Control, loosely based on XACML.

Test drive

Requirements

Before you start, you’ll need to have the following installed:

  • Java 9+ (Site is not compatible with Java 8 and below!)

  • Clojure and

  • Babashka installed on your system.

Clone this repo

$ git clone https://github.com/juxt/site

macOS (>= 10.15)

It is recommended to install openssl and openjdk and make sure JAVA_HOME is set correctly. At the time of writing brew installs openjdk 17.02 and openssl 3.0.1:

$ brew install openssl
$ echo export JAVA_HOME=/usr/local/Cellar/openjdk/17.0.2/libexec/openjdk.jdk/Contents/Home >> ~/.zshrc
$ exec zsh -l

Check that Java can find libcrypto:

$ cd site # (if needed)
$ clojure -A:dev -M:test -m kaocha.runner --focus juxt.site.authz-test

The test should run just fine. If instead $JAVA_HOME/bin/java aborts (signal 6) with the message:

$ ...
$ ... WARNING: ${JAVA_HOME}/bin/java is loading libcrypto in an unsafe way

you need to make libcrypto visible to $JAVA_HOME/bin/java by running e.g.:

$ ln -s  /usr/local/Cellar/openssl@3/3.0.1/lib/libcrypto.dylib $JAVA_HOME/lib

Configure

There’s a sample configuration in etc you should copy to $HOME/.config/site/config.edn.

$ mkdir -p $HOME/.config/site
$ cp site/etc/config.edn $HOME/.config/site/config.edn

Configure a password

Tip

If you have pass installed, this is a good time to configure a password for your superuser. We’ll assume the superuser will be named admin, but feel free to choose your own username here.

$ pass generate -n site/local/admin

Start the server

Start the Site server:

$ site/bin/site-server
Note
Alternatively, if you’re familiar with Clojure development, you can start the server via the deps.edn file and simply 'jack-in' with your editor or IDE as normal.

Start multiple instances of the server

If you require multiple Site servers to coexist on the same machine, you can start site passing a different configuration file as follows:

$ SITE_CONFIG=/absolute/path/custom-site-config.edn site/bin/site-server

In this case please be sure to change the configuration so ports are different and XTDB files are stored in a separate folder than the ones specified in the example configuration file. You’ll also need to specify Site host:port when using site commands, for example:

$ SITE_BASE_URI=http://localhost:5509 site/bin/site get-token -u admin

Start the server from the provided Docker image

Optionally, you can also get Site up and running using the provided Docker image. You need Docker installed in your system, then execute the following from the command line (sudo might not be necessary depending on your installation):

sudo docker build -t juxt/site:latest .
sudo docker run -p 2021:2021 -p 50505:50505 -d juxt/site:latest

The REPL

If you’ve run Site via your development environment and 'jacked-in' you’ll already have a REPL. Proceed to the next step.

If you’re running Site with site/bin/site-server, you’ll need to connect a terminal to Site to access the REPL. You can do this via port 50505, which is a socket REPL that Site starts by default.

How you connect to this port is up to you. One way is via ncat, but you can replace ncat with telnet, or netcat, depending on what’s available for your system.

Note

Arch users can install ncat by installing the nmap package:

$ sudo pacman -Sy nmap
$ ncat localhost 50505
Tip

Prefix the command with rlwrap if you have it installed.

$ rlwrap ncat localhost 50505

Bootstrap

Bootstrap the new system by adding the minimum resources that are required to allow remote access.

Site by JUXT. Copyright (c) 2021, JUXT LTD.
Type :repl/quit to exit

[ ]  Site API not installed.  Enter (put-site-api!) to fix this.
[ ]  Authentication resources not installed.  Enter (put-auth-resources!) to fix this.
[ ]  Role of superuser not yet created. Enter (put-superuser-role!) to fix this.
[ ]  No superusers exist. Enter (put-superuser! <username> <fullname>)
     or (put-superuser! <username> <fullname> <password>) to fix this.
site>

Install the Site API:

site> (put-site-api!)

Install the authentication rules:

site> (put-auth-resources!)

Install the superuser role:

site> (put-superuser-role!)

Finally, create a superuser. If you have pass installed, this will fetch the password directly:

site> (put-superuser! "admin" "Administrator")
Note
We recommend that you generate a password with pass.

If you don’t have pass installed, you can add a password as a final argument to put-superuser!.

site> (put-superuser! "admin" "Administrator" "admin")

Replace "admin", "Administrator" and "admin" with your own username, full name and password respectively.

Quit the REPL, for example, with Ctrl-C or by typing :repl/quit.

Run the site tool

The site tool is a command-line utility that allows you to remotely administer site.

If you’re on MacOS, you will need to install the gnu version of readlink. You can do so with brew:

brew install coreutils
ln -s /usr/local/bin/greadlink /usr/local/bin/readlink

We must first get a token that we can use for API access. This process authenticates to the site server using your password.

Here, replace admin with your username (or let it default to your OS username)
$ site/bin/site get-token -u admin

Now we can use the site tool for remote administration. Try the following:

$ site/bin/site list-users

Configure the expiry time for tokens

By default, tokens last for an hour. That can sometimes mean they expire during work sessions. You can set the expiry time of new tokens via the REPL.

(put! (assoc (e "http://localhost:2021/_site/token")  ::pass/expires-in (* 24 3600)))

License

The MIT License (MIT)

Copyright © 2020-2021 JUXT LTD.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

bidi

Bidirectional URI routing
Clojure
991
star
2

aero

A small library for explicit, intentful configuration.
Clojure
743
star
3

yada

A powerful Clojure web library, full HTTP, full async - see https://juxt.pro/yada/index.html
HTML
735
star
4

tick

Time as a value.
Clojure
599
star
5

edge

A Clojure application foundation from JUXT
Clojure
503
star
6

joplin

Flexible datastore migration and seeding for Clojure projects
Clojure
316
star
7

juxt-accounting

Double-entry accounting software written in Clojure with Datomic.
Clojure
281
star
8

pack.alpha

Package clojure projects
Java
258
star
9

mach

A remake of make (in ClojureScript)
Clojure
246
star
10

jig

Jig is an application harness providing a beautifully interactive development experience for Clojure projects.
Clojure
229
star
11

clip

Light structure and support for dependency injection
Clojure
228
star
12

iota

Infix operators for test assertions
Clojure
150
star
13

modular

JavaScript
128
star
14

apex

A compendium of Clojure libraries for implementing web backends.
Clojure
123
star
15

bolt

An integrated security system for applications built on component
Clojure
123
star
16

jinx

jinx is not xml-schema (it's json-schema!)
Clojure
99
star
17

pull

Trees from tables
Clojure
96
star
18

roll

AWS Blue/Green deployment using Clojure flavoured devops
Clojure
77
star
19

reap

A Clojure library for decoding and encoding strings used by web protocols.
Clojure
74
star
20

dirwatch

A Clojure directory watcher, wrapping the JDK 7 java.nio.file.WatchService.
Clojure
67
star
21

skip

Skippy McSkipface - A general Clojure dependency tracker
Clojure
34
star
22

snap

Snapshot testing for Clojure and Clojurescript
Clojure
30
star
23

pack-datomic

Datomic Packer and Terraform setup
HCL
26
star
24

qcon2014

JavaScript
26
star
25

stoic

Marrying the Component Lifecycle pattern with distributed config.
Clojure
20
star
26

spin

Unbundling the web application-tier
Clojure
19
star
27

pick

A Clojure library for HTTP server-driven content negotiation.
Clojure
18
star
28

prop

Clojure
17
star
29

grab

A Clojure library for parsing and executing GraphQL queries.
Clojure
16
star
30

rest

A guide to coding a REST service
CSS
15
star
31

chatserver

Clojure
13
star
32

shop

The JUXT Shop - a sample application built on Crux
Clojure
11
star
33

fuzz

Example ClojureScript Project that happens to wrap Slack
Clojure
9
star
34

dotfiles

Recommended dotfiles used by JUXT
Emacs Lisp
9
star
35

ramp

Shell
8
star
36

card

Not sure what this is. A kind-of Zettelkasten?
TypeScript
8
star
37

chatclient

Clojure
8
star
38

hire

A technical interview test for potential employees
Clojure
7
star
39

rock

Hardened AMIs for Clojure deployments (Arch Linux)
Shell
7
star
40

clip-example

Example of using Clip
Clojure
7
star
41

datomic-extras

Clojure
7
star
42

lein-dockerstalk

Clojure
7
star
43

docker

Docker files
Makefile
7
star
44

plain-clojure-lambda

A recipe for building AWS Lambdas using plain clojure
Clojure
7
star
45

draw

A DSL for SVG diagrams
Clojure
6
star
46

trag

Graph transduction
Clojure
5
star
47

radar

JUXT Clojure Technology Radar
Clojure
5
star
48

pack-ek

HCL
4
star
49

adoc

A Clojure wrapper for asciidoctorj
Clojure
4
star
50

msf

Volunteer work for MSF
Clojure
4
star
51

astro-website

Source for the main JUXT website
JavaScript
3
star
52

vext

Clojure
3
star
53

azondi

MQTT goes reactive
CSS
3
star
54

pack-riemann

HCL
3
star
55

yada.cookbook

A cookbook of yada recipes
3
star
56

component-utils

Clojure
2
star
57

blip

Small library for fetching/injecting graphql definitions
Clojure
2
star
58

ping

Clojure
2
star
59

modular.co-dependency

Co-dependency support for com.stuartsierra.component
Clojure
2
star
60

http

2
star
61

lein-deploy-tar

A Leiningen plugin to upload tars to a Maven repository.
Clojure
2
star
62

aleph-issue

Testing aleph
Clojure
1
star
63

mksmarthack

A Clojure data hack on MK:Smart
Clojure
1
star
64

eventing-examples

Clojure
1
star
65

flow

Clojure
1
star
66

training-exercises-webapp

Training exercises
Clojure
1
star
67

example-code

Example code for a recent client course
Clojure
1
star
68

home-apps

Monorepo for SPAs that use home.juxt.site as a backend
TypeScript
1
star
69

sail

Clojure
1
star
70

clojars-mirrors

Re-releasing Clojars libraries onto Maven Central
Clojure
1
star
71

XT20.conf

Public materials for XT20
1
star
72

asciidoctor-stylesheet-factory

CSS
1
star