Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mystpi/glen
🏕️ A peaceful web framework for Gleam that targets JS.
https://github.com/mystpi/glen
cloudflare-workers deno deno-deploy gleam gleam-lang javascript web web-framework
Last synced: 2 days ago
JSON representation
🏕️ A peaceful web framework for Gleam that targets JS.
- Host: GitHub
- URL: https://github.com/mystpi/glen
- Owner: MystPi
- License: mit
- Created: 2024-01-30T20:37:57.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-02-29T21:07:42.000Z (9 months ago)
- Last Synced: 2024-05-16T19:05:09.002Z (6 months ago)
- Topics: cloudflare-workers, deno, deno-deploy, gleam, gleam-lang, javascript, web, web-framework
- Language: Gleam
- Homepage: https://hexdocs.pm/glen/
- Size: 1.16 MB
- Stars: 36
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# glen
[![Package Version](https://img.shields.io/hexpm/v/glen)](https://hex.pm/packages/glen)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/glen/)🏕️ 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](https://deno.com/deploy)...and other nice-to-haves!
## Installation
Install all requirements:
```sh
gleam add glen gleam_http gleam_javascript
```Or just Glen:
```sh
gleam add glen
```## Usage
```gleam
import gleam/javascript/promise.{type Promise}
import glen
import glen/statuspub fn main() {
glen.serve(8000, handle_req)
}fn handle_req(req: glen.Request) -> Promise(glen.Response) {
"Welcome to my webpage!
Make yourself at home 😄
"
|> glen.html(status.ok)
|> promise.resolve
}
```Glen is heavily based off of [Wisp](https://github.com/gleam-wisp/wisp), and many of Wisp's [examples](https://github.com/gleam-wisp/wisp/tree/main/examples) can easily be ported to Glen. Glen also has an example application of its own in [./test](https://github.com/MystPi/glen/tree/main/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`
```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`
```gleam
import gleam/javascript/promise
import glen
import glen/statuspub fn handle_req(_req) {
"On a Cloudflare worker!"
|> glen.html(status.ok)
|> promise.resolve
}
````wrangler.toml`
```toml
main = "build/dev/javascript/my_app/index.js"
# ...
```## Docs
Documentation can be found at .
## Development & Contributing
You will need to have Gleam and a JavaScript runtime (most likely Deno) installed for developing Glen.
```sh
gleam run # Run the project
gleam test # Run the example application
```Contributions are encouraged and greatly appreciated! Please note that the [changelog](CHANGELOG.md) should be updated accordingly (this is something that everyone has trouble remembering, including me 😅).