Coder Social home page Coder Social logo

wibbuffey / slope Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 178 KB

slope.js is a web server library written in Node.js that strives to be as feature-filled as it is easy-to-use.

Home Page: https://wibbuffey.github.io/slope/

License: MIT License

JavaScript 100.00%
nodejs node node-js javascript slope webserver library javascript-library

slope's Introduction

slope.js

The webserver framework you never knew you needed!

Introduction

slope is an object-oriented zero-dependency class-driven webserver library written in Node.js. It allows the user high-level access to numerous functions that allow the user to render HTML documents, send files, return JSON data, and much more.

In short, it allows you to create a webserver like this:

const Slope = require("slope.js");
const server = new Slope.Server();

server.routes.add("/", (client, result) => {
  result.send("Hello, world!");
});

server.run();

Try it -- this is completely working Slope code! If you want to dynamically load routes, you can do something like what was described in discussion #8:

const Slope = require("slope.js");
const server = new Slope.Server();

server.routes.add("*", (client, result) => {
  try {
    require(`./routes/${client.url}`)(client, result);
  } catch (error) {
    Slope.raiseErrors(404);
  }
});

server.run();

Install

Install and update using npm:

npm i slope.js

Alternatively, for the latest and most unstable version, clone with GitHub:

gh repo clone wibbuffey/slope # download slope
cd slope                      # enter the directory

Links

If you want to follow the project or ask for help:

If you want to contribute:

slope's People

Contributors

wibbuffey avatar

Stargazers

 avatar

Watchers

 avatar

slope's Issues

Templating engine

Is your feature request related to a problem? Please describe.
N/A

Describe the solution you'd like
We should enable support for templating engines such as Jinja or the one provided in Django.

Describe alternatives you've considered
Obviously, we could simply pass the content of a file into a templating engine ourselves, but that would be more difficult than calling Slope.renderPages("template.html").

Additional context
N/A

Add custom errors

Is your feature request related to a problem? Please describe.
Allow slope to throw custom errors for semantics.

Describe the solution you'd like
Add an error/ folder containing error classes that are exported in index.md.

Slope always converts Route strings to Route RegExps

Describe the bug
Slope.Server.run() will always convert Strings to RegExps when checking if a route exists. This means that it only checks if the URL contains a route, not is a route.

To Reproduce
Steps to reproduce the behavior:

// imports, etc
const Slope = require("slope");
const server = new Slope.Server();

server.routes.add("/", (Client, Result) => {
  Result.send(`Received request: ${Client.url}`);
});

server.run();

// If you visit any URL now, because it contains "/",
// slope will show this webpage, despite it not using
// the wildcard operator ("*").

Expected behavior
Obviously, slope should only display the webpage when / is visited.

Environment

  • OS: Windows 10 (only for now!)
  • Node.js Version: 16
  • Slope Version: 1.1.3

Additional context
This bug affects practically every part of Slope code, as usually / is added FIRST, meaning that it will override all behavior. This also means the example in the README, which prides itself on being "working slope code", is broken (as of v1.1.0).

Merge `Routes` class into `Server.route()` or use the built-in `events` module

Is your feature request related to a problem? Please describe.
The Routes class is unusual, for .remove() will likely never be used in production code. Additionally, .routes having so many sub-methods feels unclean and totally breaks slope's design fundamentals.

Describe the solution you'd like
Instead, we should consider a .route() method, or better yet, use the built-in events module to provide .on() syntax (which is quite semantic).

Describe alternatives you've considered
If this fails, we could keep the original method; it works completely without flaws (even if it is unclean and breaks a few design laws).

Additional context
N/A

Create GitHub Action to automate building GitHub Pages documentation

Is your feature request related to a problem? Please describe.
We should have a GitHub Action created such that we do not need to manually update the website and wiki every time a change is made to the JSDoc source.

Describe the solution you'd like
Considering there are numerous different libraries created for the sole purpose of converting JSDoc to markdown and visa versa, we could use the following steps:

  • Rename all README.md files to index.md
  • Convert class/*.js into class/*.md (remove class/*.js afterwards)
  • Convert utils/*.js into utils/*.md (remove utils/*.js afterwards)
  • Move CODE_OF_CONDUCT.md, SECURITY.md, and CONTRIBUTING.md into .
  • Create Jekyll _config.yml
  • Commit/push to the pages branch
  • Rename class/*.md to class:-*.md and utils/*.md to utils:-*.md
  • Commit/push to wibbuffey/slope.wiki

Describe alternatives you've considered
Well, we could manually convert them like before, but that would be incredibly inefficient.

Additional context
N/A

Add support for URL parameters / fallback cases

Describe the solution you'd like
We need to add support for URL parameters (such as /api/v2/get/test) or fallback cases (if a direct route ISN'T found, run a function applicable to all pages)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.