Code Monkey home page Code Monkey logo

elemental-http-server's People

Contributors

spacetoastcoasttocoast avatar theremix avatar

Watchers

 avatar

elemental-http-server's Issues

Consider consolidating and moving auth into helper handler functions

let auth = checkAuth(request, response);

      case 'POST':

      // entire if-elseif-else block could be added into the checkAuth function
      if(auth === null) {
        response.writeHead(401, {
          'WWW-Authenticate' : 'Basic realm="Secure Area"'
        });
        response.end(notAuth);
      } else if(!auth) {
        response.writeHead(401, {
          'WWW-Authenticate' : 'Basic realm="Secure Area"'
        });
        response.end(invalidAuth);
      } else if(request.url === '/elements') {
        postHelper.incomingPost(request, response, body);
      }
      break;

Line 23 + the if-elseif-else block could be consolidated into the checkAuth function.

Then consider moving the checkAuth calls into the handlers themselves.

Your server file is gonna look hella clean after this!

Consider consolidating helper functions into own directory and having a single entry point

Currently there are 4 files in the root directory: postHelper.js, getHelper.js, putHelper.js, and deleteHelper.js.

Consider moving these files into a directory called handlers.

Then, in that same directory, have an index.js file which imports the 4 helper files. This index.js file will be your main entry point for your handlers.

Here's an example of the use case after refactoring:

// one import
const Handlers = require('./handlers/');

// useage
Handlers.GET(request, response);
Handlers.PUT(request, response);
// ...etc

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.