Code Monkey home page Code Monkey logo

http4s-laminar-stack's Introduction

http4s-laminar-stack build

This is an example of a full-stack application with the following features:

  • Scala 3 on both frontend and backend
  • Laminar as a frontend library
  • Http4s as a backend HTTP server library
  • Shared code with protocol definitions
  • Gzip compression on the server side
  • Docker packaging of the full application
  • Tests for the client with simulated DOM using jsdom

Note: this is a very basic setup, for a more complicated template (with Postgres, API spec using Smithy, etc.) please see Smithy4s Fullstack template

Additionally, you can check out my blog series about fullstack Scala 3:

  • Twotm8 - building and deploying a full-stack Scala application using Scala Native and Scala.js

  • Smithy4s - building and deploying a full-stack Scala app with Smithy4s and Scala.js

Note: this version of the template uses the latest and greatest from Cats Effect, http4s, Scala, etc. If you would like, please see the last commit that referenced old versions of the libraries. Apart from Scala 3 (which is still wonky around IntelliJ support), I highly recommend sticking with the latest versions of the libraries.

Development mode

Run in SBT (uses fast JS compilation, not optimized):

sbt> ~runDev

And open http://localhost:9000/frontend

This will restart the server on any changes: shared code, client/server, assets.

Tests

It is a prerequisite to have jsdom installed, in order for the frontend tests to run. Proposal:

yarn add jsdom

Then move into an sbt console and run tests as normal

Production mode

Run in SBT (uses full JS optimization):

sbt> ~runProd

Docker packaging

sbt> backend/docker:publishLocal

Will publish the docker image with fully optimised JS code, and you can run the container:

โœ— docker run --rm -p 8080:8080 laminar-http4s-example:0.1.0-SNAPSHOT

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Running server on http://0.0.0.0:8080 (mode: prod)

The interface is fairly simple:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.