Skip to content
ํ”„๋กœ์ ํŠธ

์†Œ๊ฐœ

๐Ÿ•๏ธ A peaceful web framework for Gleam that targets JS.

์›น ๋ฐ ์•ฑ ๊ฐœ๋ฐœ

์ด ์ˆ˜์น˜๋ฅผ ์ธก์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•

์ธก์ •๋œ ์Šคํƒ€ ์ฆ๊ฐ€

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
๊ธฐ๋ก ์ˆ˜์ง‘ ์ค‘

์„œ๋กœ ๊ฒน์น˜๋Š” ๊ธฐ๊ฐ„์˜ ์ˆœ์ฆ๊ฐ€๋Ÿ‰์ด๋ฉฐ ์ผ๋ณ„ ํ•ฉ๊ณ„๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ์ธก์ •๊ฐ’์ด ์—†์œผ๋ฉด ๋น„์›Œ ๋‘ก๋‹ˆ๋‹ค. ์Šคํƒ€๋Š” ๊ด€์‹ฌ๋„๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ ํ’ˆ์งˆ์„ ๋ณด์žฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

README.md

Original

glen

Package Version Hex Docs

๐Ÿ•๏ธ A peaceful web framework for Gleam that targets JS.

โœจ Features:

  • Request & response helpers
  • Helpful middleware
  • File streaming
  • Websockets
  • Bring-your-own server (optional)
  • Easily deploy on serverless platforms such as Deno Deploy

...and other nice-to-haves!

Installation

Install all requirements:

gleam add glen gleam_http gleam_javascript

Or just Glen:

gleam add glen

Usage

import gleam/javascript/promise.{type Promise}
import glen
import glen/status

pub fn main() {
  glen.serve(8000, handle_req)
}

fn handle_req(req: glen.Request) -> Promise(glen.Response) {
  "<h1>Welcome to my webpage!</h1>
  <p>Make yourself at home ๐Ÿ˜„</p>"
  |> glen.html(status.ok)
  |> promise.resolve
}

Glen is heavily based off of Wisp, and many of Wisp's examples can easily be ported to Glen. Glen also has an example application of its own in ./test.

Bring-your-own server

Glen's serve function only works on the deno runtime, but you can bring your own server so Glen can work on any runtime, such as Node.js (>= v17.0.0) or Cloudflare Workers. The convert_request and convert_response functions are here to help you with this.

Cloudflare Workers example

Glen's static middleware will not work on the Cloudflare Workers runtime since it does not support the node:fs module. Everything else should work as expected.

src/index.js

import * as glen from '../glen/glen.mjs';
import * as my_app from './my_app.mjs';

export default {
  async fetch(request, _env, _ctx) {
    const req = glen.convert_request(request);
    const response = await my_app.handle_req(req);
    const res = glen.convert_response(response);

    return res;
  },
};

src/my_app.gleam

import gleam/javascript/promise
import glen
import glen/status

pub fn handle_req(_req) {
  "On a Cloudflare worker!"
  |> glen.html(status.ok)
  |> promise.resolve
}

wrangler.toml

main = "build/dev/javascript/my_app/index.js"
# ...

Docs

Documentation can be found at https://hexdocs.pm/glen.

Development & Contributing

You will need to have Gleam and a JavaScript runtime (most likely Deno) installed for developing Glen.

gleam run   # Run the project
gleam test  # Run the example application

Contributions are encouraged and greatly appreciated! Please note that the changelog should be updated accordingly (this is something that everyone has trouble remembering, including me ๐Ÿ˜…).

๊ด€๋ จ ํ”„๋กœ์ ํŠธ ์‚ดํŽด๋ณด๊ธฐ

๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘โ€ฆ