Coder Social home page Coder Social logo

hviana / faster Goto Github PK

View Code? Open in Web Editor NEW
33.0 33.0 8.0 16 KB

A fast and optimized middleware server with an absurdly small amount of code (300 lines) built on top of Deno's native HTTP APIs with no dependencies. It also has a collection of useful middlewares: log file, serve static, CORS, session, rate limit, token, body parsers, redirect, proxy and handle upload. In "README" there are examples of all the resources. Faster's ideology is: all you need is an optimized middleware manager, all other functionality is middleware.

License: MIT License

TypeScript 100.00%

faster's People

Contributors

exside avatar hviana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

faster's Issues

FR: add prefix option for .use()

Hi,
Thanks for giving from your time and creating a small, super-fast server library for Deno!

I'd like to ask for a feature;

In express.js (and many others) you can set a prefix for the routes you define, in the following way:

import { usersRoute } from "./users.ts"
import { teamsRoute } from "./teams.ts"
import { v2Route } from "./v2.ts"

const route = new Route()
route.use('/users', usersRoute)
route.use('/teams', teamsRoute)
route.use('/api/v2', v2Route)

route.get(
  '/',
  res('json'),
  req('json'),
  async (ctx: any, next: any) => { ... } // etc
)

The use-case here is to give a prefix to all the routes in usersRoute, teamsRoute..
Then, if in usersRoute I defined the following route:

route.get(
  '/payments',
  res('json'),
  req('json'),
  async (ctx: any, next: any) => { ... } // etc
)

then it will be served in localhost:80/users/payments.

If you prefer me to work on it and create a PR, I'll be happy to.
Thanks in advance

Serve static for both GET and HEAD requests breaks server

Hi, first of all, great work on faster, love it so far!

I'm running into an issue when trying to handle HEAD requests (using them from the frontend to see if i need to fetch the entire file or if i can used the cached version in the browser, e.g. to check if the file was changed) for static files while also serving them statically via GET requests, i have this (played around with the order of the blocks, but no change):

server.get(
	'/www/*',
	serveStatic('./www'),
);

server.head(
	'/www/*',
	serveStatic('./www'),
);

// also tried the following with no change in behaviour
server.get(
	'/www/*',
	serveStatic('./www'),
	async (ctx, next) => {
		await next();
	},
);

server.head(
	'/www/*',
	serveStatic('./www'),
	async (ctx, next) => {
		await next();
	},
);

when the server.head() handler is present, the HEAD requests work fine, but the GET requests stop working and stay as (pending) forever in the network monitor (browser side), if i remove it, HEAD requests return a 404 and the GET requests work as expected. I'm not sure where the issue is, i don't get errors on the server side and neither in the browser, the GET request is just stuck. Any ideas why that could be? maybe using the same middleware twice? but i checked the code, don't see why that would be an issue.

How to serve static files?

import {
  req,
  res,
  Server,
  serveStatic,
} from "https://deno.land/x/faster/mod.ts";

const port = parseInt(Deno.env.get("PORT") || "8080");


const server = new Server();

server.get(
    "/*",
    serveStatic("./dist"),
  );

console.log(`๐Ÿš€ Listening on port ${port}: http://localhost:${port}`);
await server.listen({ port});

./dist is a regular web app, with ./dist/index.html and other assets. This content is served by other file servers no problem.

This fails: with the browser pointing to http://localhost:3000

โฏ PORT=3000 deno run --allow-all --unstable server.ts
๐Ÿš€ Listening on port 3000: http://localhost:3000
Error: Is a directory (os error 21)
    at async read (ext:deno_io/12_io.js:108:17)
    at async Object.pull (https://deno.land/[email protected]/streams/readable_stream_from_reader.ts:59:22)

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.