Skip to content

GraphiCode-Inc/Aetherx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📂 AETHERX

UltraFast Server – Lightweight Bun-powered HTTP framework with routes, middleware, plugins, request/response management, and modern logging

npm version npm downloads Discord


📦 Installation

npm install aetherx
# or
yarn add aetherx
# or
bun add aetherx

Note: Bun must be installed globally:

npm install -g bun

🚀 Running HTTP Server

import { Sether } from "aetherx";

const server = new Sether({
  port: 3000,
  settings: {
    logger: true,
    development: false,
    error: new Response(`<pre>500 Internal Server Error</pre>`, {
      status: 500,
      headers: { "Content-Type": "text/html" },
    }),
  },
});

🛣️ Adding Routes

app.get("/", (req, res) => res.status(200).text("Welcome!"));
app.get("/html", (req, res) => res.render("./src/pages/index.html"));
app.get("/ejs", (req, res) => 
  res.render("./src/pages/index.ejs", { title: "EJS Page" }) // requires npm i ejs
);

📌 Aether Router

import { Sether, Router } from "aetherx";

const router = new Router();

router.create({
  routeName: "myUserRoute",
  name: "/user",
  category: "/api",
  method: "get",
  run: (req, res) => res.render("./src/pages/index.html"),
});

router.create({
  routeName: "userProfile",
  name: "/user/profile",
  category: "/api",
  method: "get",
  run: (req, res) => res.render("./src/pages/profile.html"),
});

const server = new Sether({
  port: 3000,
  routes: ["myUserRoute", "userProfile"], // routeName references
  settings: {
    logger: true,
    development: false,
    error: new Response(`<pre>500 Internal Server Error</pre>`, {
      status: 500,
      headers: { "Content-Type": "text/html" },
    }),
  },
});

🔌 Plugins

Available plugins: AI, CORS, Helmet, RateLimit

import { Sether, AiPlugin, chat, CorsPlugin, HelmetPlugin, RateLimitPlugin } from "aetherx";

const server = new Sether({
  port: 3000,
  plugins: [
    new AiPlugin({
      apiKey: "YOUR_OPENAI_KEY",
      model: "gpt-4",
      chat: async (messages) => await chat("gemini", messages)
    }),
    new HelmetPlugin({
      contentSecurityPolicy: true,
      referrerPolicy: "no-referrer",
      xssProtection: true
    }),
    new CorsPlugin({
      origin: "*",
      methods: ["GET", "POST"],
      credentials: true
    }),
    new RateLimitPlugin({
      windowMs: 60000,
      max: 100,
      identifier: (req) => req.ip || "anon"
    }),
  ],
  settings: {
    logger: true,
    development: false,
  },
});

// Using AI chat
const reply = await chat("gemini", [
  { role: "user", content: "Hello Gemini!" }
]);
console.log(reply); // Gemini's response

🗓️ Events

server.on("ready", () => console.log("Server started!"));

server.emit("yourCustomEvent", "args");

server.on("yourCustomEvent", (...args) => console.log("Event triggered:", args));

⚡ API

Sether (Server)

Method Description
on(event: string, callback) Listen for server events
emit(event: string, ...args) Emit custom events
routes Array of route names to register
plugins Array of plugins to use

Router

Method Description
create(params) Create a new route
getRouter() Return all routes
findRoute(name, method) Find a route by name and method

ReqManager

Method Description
json() Parse request body as JSON
text() Get raw text body
form() Parse as FormData
getHeader(name) Get specific header
getQuery(key, default) Get query param
getParam(key) Get route param
device() Detect device/browser info
ip Get client IP

ResponseBuilder

Method Description
status(code) Set response status
json(data) Send JSON response
text(data) Send plain text response
render(path, data) Render HTML/EJS template

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •