From 82dbfa71bdcf69c88e6a822247bd5057139f1908 Mon Sep 17 00:00:00 2001 From: ludwigsw Date: Wed, 8 May 2024 19:28:24 +0200 Subject: [PATCH] init --- .github/workflows/test.yml | 23 +++++++++++++++++++++++ .gitignore | 4 ++++ README.md | 25 +++++++++++++++++++++++++ gleam.toml | 13 +++++++++++++ src/apero_webapp.gleam | 5 +++++ src/app.gleam | 25 +++++++++++++++++++++++++ src/app/router.gleam | 0 test/apero_webapp_test.gleam | 12 ++++++++++++ 8 files changed, 107 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 gleam.toml create mode 100644 src/apero_webapp.gleam create mode 100644 src/app.gleam create mode 100644 src/app/router.gleam create mode 100644 test/apero_webapp_test.gleam diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..916edea --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: test + +on: + push: + branches: + - master + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: erlef/setup-beam@v1 + with: + otp-version: "26.0.2" + gleam-version: "1.0.0" + rebar3-version: "3" + # elixir-version: "1.15.4" + - run: gleam deps download + - run: gleam test + - run: gleam format --check src test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/README.md b/README.md new file mode 100644 index 0000000..915eb97 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# apero_webapp + +[![Package Version](https://img.shields.io/hexpm/v/apero_webapp)](https://hex.pm/packages/apero_webapp) +[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/apero_webapp/) + +```sh +gleam add apero_webapp +``` +```gleam +import apero_webapp + +pub fn main() { + // TODO: An example of the project in use +} +``` + +Further documentation can be found at . + +## Development + +```sh +gleam run # Run the project +gleam test # Run the tests +gleam shell # Run an Erlang shell +``` diff --git a/gleam.toml b/gleam.toml new file mode 100644 index 0000000..061e78f --- /dev/null +++ b/gleam.toml @@ -0,0 +1,13 @@ +name = "app" +version = "1.0.0" +description = "A Wisp example" +gleam = ">= 0.32.0" + +[dependencies] +gleam_stdlib = "~> 0.30" +wisp = { path = "../.." } +gleam_erlang = "~> 0.23" +mist = "~> 0.14" + +[dev-dependencies] +gleeunit = "~> 1.0" \ No newline at end of file diff --git a/src/apero_webapp.gleam b/src/apero_webapp.gleam new file mode 100644 index 0000000..4602ee4 --- /dev/null +++ b/src/apero_webapp.gleam @@ -0,0 +1,5 @@ +import gleam/io + +pub fn main() { + io.println("Hello from apero_webapp!") +} diff --git a/src/app.gleam b/src/app.gleam new file mode 100644 index 0000000..1c3052c --- /dev/null +++ b/src/app.gleam @@ -0,0 +1,25 @@ +import gleam/erlang/process +import mist +import wisp +import app/router + +pub fn main() { + // This sets the logger to print INFO level logs, and other sensible defaults + // for a web application. + wisp.configure_logger() + + // Here we generate a secret key, but in a real application you would want to + // load this from somewhere so that it is not regenerated on every restart. + let secret_key_base = wisp.random_string(64) + + // Start the Mist web server. + let assert Ok(_) = + wisp.mist_handler(router.handle_request, secret_key_base) + |> mist.new + |> mist.port(8000) + |> mist.start_http + + // The web server runs in new Erlang process, so put this one to sleep while + // it works concurrently. + process.sleep_forever() +} diff --git a/src/app/router.gleam b/src/app/router.gleam new file mode 100644 index 0000000..e69de29 diff --git a/test/apero_webapp_test.gleam b/test/apero_webapp_test.gleam new file mode 100644 index 0000000..3831e7a --- /dev/null +++ b/test/apero_webapp_test.gleam @@ -0,0 +1,12 @@ +import gleeunit +import gleeunit/should + +pub fn main() { + gleeunit.main() +} + +// gleeunit test functions end in `_test` +pub fn hello_world_test() { + 1 + |> should.equal(1) +}