From dfe0d520806ece23374d83475971d5f4ee704ef5 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Wed, 16 Feb 2022 19:21:51 +1100 Subject: [PATCH] v0.2.0 --- .gitignore | 1 + CHANGELOG.md | 2 +- README.md | 12 +++++----- mod.ts | 1 - storage/drivers/postgres.ts | 6 ++--- test.tsx | 45 ------------------------------------- 6 files changed, 11 insertions(+), 56 deletions(-) create mode 100644 .gitignore delete mode 100644 test.tsx diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb76ed..18e2f09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## v0.2.0 (wip) +## v0.2.0 (2022-02-16) ### Added diff --git a/README.md b/README.md index 090d648..3bbeb6d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # 🐍 nadder -**nadder** is an opinionated HTTP/WebSocket server framework for Deno. +**nadder** is an opinionated web server framework for Deno. -It includes **[URL Pattern](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API)** +It includes [URL Pattern](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) routing, post-route middleware, helpers for creating/reading/manipulating cookies and responses, upgrading HTTP connections to WebSocket connections (inc. sorting into channels), -**PostgreSQL** (or in-memory) session storage (inc. garbage collection and expiry), a React-free -**JSX transformer** and atomic CSS with [**Uno**](https://github.com/unocss/unocss). +PostgreSQL (or in-memory) session storage (inc. garbage collection and expiry), a React-free +JSX transformer and atomic CSS with [Uno](https://github.com/unocss/unocss). ## Quick start @@ -51,12 +51,12 @@ nadder.handleRoute('GET', '/{index.html}?', async (ctx) => { nadder.listenAndServe(); ``` -All other features are also made available as exports of the `mod.ts` file. +All features are made available as exports of the `mod.ts` file +and documented in the `types.ts` file. For convenience, the following dependencies are re-exported: - `setCookie`, `deleteCookie`, `Cookie`, `HTTPStatus` and `HTTPStatusText` from [`std/http`](https://deno.land/std/http). -- `contentType` from [`https://deno.land/x/media_types`](https://deno.land/x/media_types) --- diff --git a/mod.ts b/mod.ts index 0220b8f..5ec14c7 100644 --- a/mod.ts +++ b/mod.ts @@ -6,7 +6,6 @@ export * as default from "./server.ts"; -export { contentType } from "./deps.ts"; export { HTTPStatus, HTTPStatusText } from "./deps.ts"; export { deleteCookie, setCookie } from "./deps.ts"; diff --git a/storage/drivers/postgres.ts b/storage/drivers/postgres.ts index b020776..f9f25ce 100644 --- a/storage/drivers/postgres.ts +++ b/storage/drivers/postgres.ts @@ -7,11 +7,11 @@ import { postgres } from "../../deps.ts"; const postgresConnection = ({ - user = "postgres", + user = Deno.env.get("POSTGRES_USER") ?? "postgres", password = Deno.env.get("POSTGRES_PWD"), hostname = Deno.env.get("POSTGRES_HOST"), - port = "6543", - database = "postgres", + port = Deno.env.get("POSTGRES_PORT") ?? "6543", + database = Deno.env.get("POSTGRES_DB") ?? "postgres", } = {}) => { // creates lazy/on-demand connections // for concurrent query execution handling diff --git a/test.tsx b/test.tsx deleted file mode 100644 index c50deb7..0000000 --- a/test.tsx +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @jsx h - * @jsxFrag jsxFrag - */ - -import "https://deno.land/x/dotenv/load.ts"; - -import nadder, { - Document, - h, - jsxFrag, - postgresConnection, - postgresSession, -} from "./mod.ts"; - -const postgres = postgresConnection({ - password: Deno.env.get("POSTGRES_PWD"), - hostname: Deno.env.get("POSTGRES_HOST"), - }), - session = await postgresSession(postgres); - -nadder.handleRoute("GET", "/{index.html}?", async (ctx) => { - const count = (((await session.get(ctx, "count")) as number) ?? -1) + 1; - await session.set(ctx, "count", count); - - ctx.res.body = await Document( - "Home", - <> -

Hello world!

-

- Page load count: {count} -

- , - ); - ctx.res.inferContentType("html"); - - const socket = ctx.upgrade.socket(); - if (!socket) return; - socket.onmessage = (ev) => { - if (ev.data === "channel") ctx.upgrade.channel.join("channel2"); - ctx.upgrade.channel.broadcast(ev.data); - }; -}); - -nadder.listenAndServe();