Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🏕️ A peaceful web framework for Gleam that targets JS.

License

NotificationsYou must be signed in to change notification settings

MystPi/glen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Package VersionHex 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 asDeno Deploy

...and other nice-to-haves!

Installation

Install all requirements:

gleam add glen gleam_http gleam_javascript

Or just Glen:

gleam add glen

Usage

importgleam/javascript/promise.{typePromise}importglenimportglen/statuspubfnmain(){glen.serve(8000,handle_req)}fnhandle_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 ofWisp, and many of Wisp'sexamples can easily be ported to Glen. Glen also has an example application of its own in./test.

Bring-your-own server

Glen'sserve function only works on thedeno 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. Theconvert_request andconvert_response functions are here to help you with this.

Cloudflare Workers example

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

src/index.js

import*asglenfrom'../glen/glen.mjs';import*asmy_appfrom'./my_app.mjs';exportdefault{asyncfetch(request,_env,_ctx){constreq=glen.convert_request(request);constresponse=awaitmy_app.handle_req(req);constres=glen.convert_response(response);returnres;},};

src/my_app.gleam

importgleam/javascript/promiseimportglenimportglen/statuspubfnhandle_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 athttps://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 projectgleamtest# Run the example application

Contributions are encouraged and greatly appreciated! Please note that thechangelog should be updated accordingly (this is something that everyone has trouble remembering, including me 😅).


[8]ページ先頭

©2009-2025 Movatter.jp