furkan3ayraktar / clojure-polylith-realworld-example-app

Clojure, Polylith and Ring codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
MIT License
449 stars 79 forks source link

Start REPL with Zero Prompt Calva Jack-In #29

Closed PEZ closed 1 year ago

PEZ commented 1 year ago

Adapting the example to utilize the changes in this PR:

NB: Don't merge until ^that^ PR is merged into Calva

I also made the jack-in sequence automatically start the API server. Dunno if you had reasons not to do it that way?

There are to connect sequences defined here, one for jack-in and one for connecting to a running REPL. The latter opens up for two workflows:

  1. You start the REPL via the integrated VS Code terminal, and then connect to the REPL, with zero prompts, and start the app via the server.clj code.
    • If you need to reload the VS Code window (maybe because of updating the Calva extension or some other extension) you can do so and Calva will reconnect the repl automatically, without it losing any state.
  2. You start the REPL via a terminal external to VS Code, and then connect to the REPL, with zero prompts, and start the app via the server.clj code.
    • Same benefits as with 1.
    • You can close VS Code and when you open the project again, Calva will automatically reconnect to the REPL with all state intact.

Apropos the change in env.edn

When I started the ClojureScript conduit example, I ran into CORS troubles. I already had a server running at port 3000, causing the conduit web server to start at port 3001. Figured that this app could be prepared for that scenario. 😄

Maybe I did something wrong there because I diden't get the conduit app to work. I still get a CORS error in the dev console. And on the server I see this in the Jack-in terminal:

2023-03-10T07:51:55.591Z Pappas-data.local INFO [ring.logger.timbre:13] - Starting :options /api/users for [0:0:0:0:0:0:0:1] {"origin" "http://localhost:3001", "sec-fetch-site" "same-site", "host" "localhost:6003", "user-agent" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36", "access-control-request-headers" "content-type", "referer" "http://localhost:3001/", "connection" "keep-alive", "pragma" "no-cache", "accept" "*/*", "accept-language" "en,en-US;q=0.9", "access-control-request-method" "POST", "sec-fetch-dest" "empty", "accept-encoding" "gzip, deflate, br", "sec-fetch-mode" "cors", "cache-control" "no-cache"}
2023-03-10T07:51:55.592Z Pappas-data.local DEBUG [ring.logger.timbre:13] - Request details: {:remote-addr "[0:0:0:0:0:0:0:1]", :server-port 6003, :content-length nil, :content-type nil, :character-encoding nil, :uri "/api/users", :server-name "localhost", :query-string nil, :scheme :http, :request-method :options}
2023-03-10T07:51:55.592Z Pappas-data.local INFO [ring.logger.timbre:13] -   \ - - - -  Params: {}
2023-03-10T07:51:55.592Z Pappas-data.local INFO [ring.logger.timbre:13] - Finished :options /api/users for [0:0:0:0:0:0:0:1] in (1 ms) Status: 200
2023-03-10T07:51:55.596Z Pappas-data.local INFO [ring.logger.timbre:13] - Starting :post /api/users for [0:0:0:0:0:0:0:1] {"origin" "http://localhost:3001", "sec-fetch-site" "same-site", "sec-ch-ua-mobile" "?0", "host" "localhost:6003", "user-agent" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36", "content-type" "application/json", "content-length" "56", "sec-ch-ua" "\"Chromium\";v=\"110\", \"Not A(Brand\";v=\"24\", \"Brave\";v=\"110\"", "sec-ch-ua-platform" "\"macOS\"", "referer" "http://localhost:3001/", "connection" "keep-alive", "pragma" "no-cache", "accept" "application/json", "accept-language" "en", "sec-fetch-dest" "empty", "accept-encoding" "gzip, deflate, br", "sec-fetch-mode" "cors", "sec-gpc" "1", "cache-control" "no-cache"}
2023-03-10T07:51:55.596Z Pappas-data.local DEBUG [ring.logger.timbre:13] - Request details: {:remote-addr "[0:0:0:0:0:0:0:1]", :server-port 6003, :content-length 56, :content-type "application/json", :character-encoding "UTF-8", :uri "/api/users", :server-name "localhost", :query-string nil, :scheme :http, :request-method :post}
2023-03-10T07:51:55.597Z Pappas-data.local INFO [ring.logger.timbre:13] -   \ - - - -  Params: {:user {:username "P", :email "p@p.p", :password "[REDACTED]"}}
2023-03-10T07:51:55.598Z Pappas-data.local INFO [ring.logger.timbre:13] - Finished :post /api/users for [0:0:0:0:0:0:0:1] in (2 ms) Status: 422

I should probably test with some other conduit app, but I am running out of time here. Maybe you can see what I did wrong?

furkan3ayraktar commented 1 year ago

This is great! Thank you for the quick changes to Calva!

I also made the jack-in sequence automatically start the API server. Dunno if you had reasons not to do it that way?

I think you added the sequence back then, and I did not check it 😂 I think it makes sense to start the server.

I will investigate the CORS issue and ensure this project can be started and connected to a conduit frontend with minimal steps.

PEZ commented 1 year ago

I also made the jack-in sequence automatically start the API server. Dunno if you had reasons not to do it that way?

I think you added the sequence back then, and I did not check it 😂

🤣

This should be good to now, afaik. I used this project as one of my drivers when making the changes to Calva.

furkan3ayraktar commented 1 year ago

I've re-worded comments in the settings.json and restructured the Readme. I also ran it against the jacekschae/conduit frontend. I didn't get any CORS issues. Just changing api-url in src/conduit/events.cljs file to (def api-url "http://localhost:6003/api") was enough to get it work.