diff --git a/litestar/README.md b/litestar/README.md new file mode 100644 index 00000000..9ea2440e --- /dev/null +++ b/litestar/README.md @@ -0,0 +1,22 @@ +# Litestar + +Created By: Jacob Coffee + +# About +This is a starter template in Python for building a [Litestar](https://litestar.dev) application + +# Try it out + + + + + Open in IDX + + diff --git a/litestar/dev.nix b/litestar/dev.nix new file mode 100644 index 00000000..a8312341 --- /dev/null +++ b/litestar/dev.nix @@ -0,0 +1,36 @@ +{ pkgs, ... }: { + # Which nixpkgs channel to use. + channel = "stable-24.05"; # or "unstable" + # Use https://search.nixos.org/packages to find packages + packages = [ + pkgs.python3 + pkgs.python312Packages.pip + pkgs.python312Packages.litestar + pkgs.python312Packages.uvicorn + ]; + # Sets environment variables in the workspace + env = {}; + idx = { + previews = { + enable = true; + previews = { + web = { + command = [ "./devserver.sh" ]; + env = { PORT = "$PORT"; }; + manager = "web"; + }; + }; + }; + # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" + extensions = [ "ms-python.python" "rangav.vscode-thunder-client" ]; + workspace = { + # Runs when a workspace is first created with this `dev.nix` file + onCreate = { + install = + "python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt"; + # Open editors for the following files by default, if they exist: + default.openFiles = [ "app.py" ]; + }; + }; + }; +} diff --git a/litestar/dev/app.py b/litestar/dev/app.py new file mode 100644 index 00000000..6295face --- /dev/null +++ b/litestar/dev/app.py @@ -0,0 +1,19 @@ +from litestar import Litestar, get +from litestar.config.cors import CORSConfig +import uvicorn + +@get("/") +async def home() -> dict: + return {"message": "Now you can effortlessly create a REST API with Litestar!"} + +cors_config = CORSConfig( + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +app = Litestar(route_handlers=[home], cors_config=cors_config) + +if __name__ == "__main__": + uvicorn.run(app, host="0.0.0.0") diff --git a/litestar/dev/devserver.sh b/litestar/dev/devserver.sh new file mode 100644 index 00000000..28c37f69 --- /dev/null +++ b/litestar/dev/devserver.sh @@ -0,0 +1,3 @@ +#!/bin/sh +source .venv/bin/activate +litestar run --debug --reload \ No newline at end of file diff --git a/litestar/dev/requirements.txt b/litestar/dev/requirements.txt new file mode 100644 index 00000000..282e0510 --- /dev/null +++ b/litestar/dev/requirements.txt @@ -0,0 +1,3 @@ +pip +litestar +uvicorn \ No newline at end of file diff --git a/litestar/idx-template.json b/litestar/idx-template.json new file mode 100644 index 00000000..97c145cb --- /dev/null +++ b/litestar/idx-template.json @@ -0,0 +1,11 @@ +{ + "name": "Litestar", + "description": "Effortlessly build performant APIs with Litestar - The powerful, lightweight and flexible ASGI framework", + "categories": [ + "Web app", + "Backend" + ], + "icon": "https://github.com/litestar-org/branding/blob/6a4f90f42dbc5412c39a138fb5b8e6a3cd489590/assets/Branding%20-%20SVG%20-%20Transparent/Logo%20-%20Blue%20and%20Yellow.svg", + "website": "https://litestar.dev/", + "publisher": "Jacob Coffee" + } \ No newline at end of file diff --git a/litestar/idx-template.nix b/litestar/idx-template.nix new file mode 100644 index 00000000..cba3fdb7 --- /dev/null +++ b/litestar/idx-template.nix @@ -0,0 +1,16 @@ +{ pkgs, ... }: { + packages = [ + pkgs.python3 + pkgs.python312Packages.pip + pkgs.python312Packages.litestar + pkgs.python312Packages.uvicorn + ]; + bootstrap = '' + mkdir "$out" + mkdir -p "$out/.idx/" + cp -rf ${./dev.nix} "$out/.idx/dev.nix" + shopt -s dotglob; cp -r ${./dev}/* "$out" + chmod -R +w "$out" + chmod +rwx "$out/devserver.sh" + ''; +} \ No newline at end of file