Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Hafsa Jabeen
Hafsa Jabeen

Posted on • Originally published atcodesphere.com on

How to Deploy Gleam on Codesphere?

How to Deploy Gleam on Codesphere?

Gleam is a newly released language, claimed to be optimized for concurrency and refactoring. It is compact and easy-to-learn (as per the creators you can learn it in an afternoon). This Elm and Rust-inspired language has a compiler that serves as a programming assistant. To sum up some of the features of Gleam, we can say its small surface area gives it the simplicity of Go while also enabling you to leverage Erlang and Elixir tools. In addition, it is type-safe, and functional, as well as highly scalable.

Gleam can run on JS runtimes, which means you can run it anywhere including (but not limited to) mobile devices and browsers. Let’s create a Gleam project for a simple backend web application. Once the project is set up, we'll proceed to deploy it onCodesphere.

Creating a Gleam Project

We are going to work on a simple Gleam backend web application and deploy it on Codesphere. Let’s start by creating a gleam project.

gleam new my_web_app
Enter fullscreen modeExit fullscreen mode

Replace “my_web_app” with the name you want to give to your project. It will create a Gleam project, you can then run this command to go to your project directory.

cd my_web_app
Enter fullscreen modeExit fullscreen mode

Now open src/my_web_app.gleam file and write this code.

mport gleam/ioimport mistimport gleam/erlang/processimport gleam/bytes_builderimport gleam/http/response.{Response}pub fn main() {  let assert Ok(_) =    web_service    |> mist.new    |> mist.port(3000)    |> mist.start_http  process.sleep_forever()}fn web_service(_request) {  let body = bytes_builder.from_string("Hello, Gleam!")  Response(200, [], mist.Bytes(body))}
Enter fullscreen modeExit fullscreen mode

Running Gleam on Codesphere

It is pretty straightforward to run gleam on Codesphere. All you have to do is create a ci.yml file in your project directory and replace the contents with this.

prepare:  steps:    - command: "nix-env -iA nixpkgs.gleam"    - command: "nix-env -iA nixpkgs.erlang"    - command: "nix-env -iA nixpkgs.rebar3"    - command: gleam add mist gleam_http gleam_erlangtest:  steps: []run:  steps:    - command: gleam run
Enter fullscreen modeExit fullscreen mode

This will install Gleam and all the required dependencies like Erlang, Rebar, and Mist to run this web application. Go to CI pipeline, hit prepare and run stages and your Gleam web application will be up and running in no time.

You can access the code here from theGitHub repository.

I hope you enjoyed exploring Gleam as much as I did!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Learning and sharing knowledge as I go
  • Location
    Karlsruhe, Germany
  • Work
    Technical Marketing Engineer at Codesphere
  • Joined

More fromHafsa Jabeen

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp