generated from FiV0/clj-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,60 @@ | ||
# {project} | ||
# spa-ws-template | ||
|
||
Executing the program can either be done via | ||
``` | ||
clj -M -m scratch :arg1 :arg2 | ||
``` | ||
or by compiling a jar via | ||
This project is an example of a [Reagent](https://github.com/reagent-project/reagent)/[ReFrame](https://github.com/Day8/re-frame) | ||
frontend together with [http-kit](https://github.com/http-kit/http-kit) as a server and a websocket with | ||
[sente](https://github.com/ptaoussanis/sente). | ||
|
||
### Getting started | ||
|
||
To install the required JS libraries you need to (once) run: | ||
```bash | ||
yarn install | ||
``` | ||
clj -T:build clean | ||
clj -T:build jar | ||
|
||
To start [shadow-cljs](https://github.com/thheller/shadow-cljs) and get a cljs repl do. | ||
```clj | ||
(require '[shadow.cljs.devtools.api :as shadow] | ||
'[shadow.cljs.devtools.server :as server]) | ||
|
||
(server/start!) | ||
(shadow/watch :app) | ||
(shadow/repl :app) | ||
``` | ||
and executing it via | ||
To start the server on port 5000 | ||
```clj | ||
(require '[io.dbme.server :as server]) | ||
|
||
(server/start!) | ||
``` | ||
java -jar target/lib-0.1.4.jar :arg1 :arg2 | ||
|
||
You should then be able to see the frontend at [localhost:5000](http://localhost:5000). | ||
|
||
If you are using [CIDER](https://github.com/clojure-emacs/cider) you can also just jack-in via | ||
`cider-jack-in-clj&cljs`. | ||
|
||
### Sending stuff over the websocket. | ||
|
||
The frontend then should look something like | ||
|
||
. | ||
|
||
Once you connect, you should see a log message in your clj repl telling you that a connection | ||
has been established. | ||
|
||
Now you are able to send stuff over the websocket connection. You can add some clojure data in the send | ||
field, for example `{:hello :world}`. Once you hit send you should once again see a log message | ||
with the data in your server repl. | ||
|
||
For sending stuff from server to client you can look at the [socket](src/io/dbme/socket.clj) namespace. | ||
```clj | ||
(require '[io.dbme.socket :as socket]) | ||
|
||
(send-data {:some-new-data true}) | ||
``` | ||
The data you send is then displayed above the send field in the frontend. | ||
|
||
Happy hacking! | ||
|
||
## License | ||
|
||
MIT Licence |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.