Giter Site home page Giter Site logo

pablopunk / iga Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 565 KB

Zero config typescript/es6 server with the filesystem as the router

Home Page: https://pablopunk.com/iga

JavaScript 96.83% TypeScript 3.17%
api nextjs routes automatic es6 typescript zero-config easy quick fast server nodejs

iga's People

Contributors

dependabot[bot] avatar pablopunk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

iga's Issues

in-memory cache

  • One for request.url with {body, code}
  • One for endpoint handlers (like the one that's on master but with a new module)

This cache will improve requests/sec by 10x based on my experiments

Export a handler instead of creating the server

Make src/index.js export the handler, no need to create the server in that library. This way I can use it as a middleware with any server, while keeping the ability to create a server inside src/cli.js.

This will allow easier deployments, for example compatibility with now 2.0 lambdas.

NOTE: This means all manual cache mechanisms should be implemented where the server is implemented i.e the CLI. Http cache will still be managed in the library (manually) but for example handlers cache should be moved to the CLI. This affects #6

typescript

Use typescript with sucrase if the file is ts

Extend response and request objects

Right now both are the standard NodeJS http response and request objects. It's okay because people know how to use them and they're very well documented, but I would like to add a bit more functionality to both objects.

Some ideas:

  • request.query: An object using require('url').parse
  • reponse.json: Sets headers for JSON and accepts an object (that will get stringified before sending)
  • return object | string | number: Instead of using the response object, it would be usefull to just return a value. An object should be sent as a json, a string as text, and the number could just be the status code.

Example:

// find-user.js
export default (req, res) => {
  if (!req.query.id) {
    return 403
  }

  const id = req.query.id
  const user = getUserById(id)

  if (!user) {
    return 404
  }

  return { items: [user] }
  // or res.json({ items: [user] })
}
  • json
  • string
  • query params
  • status code

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.