Skip to content

brustolin/httpcontroller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Http Controller

A Node.js module to run http server based on view/controllers.

Installation

npm install httpcontroller --save

Simplest Usage

const httpcontroller = require('httpcontroller');

const server = new httpcontroller.HttpServer("<html><body><h1>Hello World!</h1></body></html>");
server.start();
To test this code open the browser at http://localhost/

Static Site

const httpcontroller = require('httpcontroller');

const server = new httpcontroller.HttpServer(httpcontroller.StaticHandler); 
//or const server = new httpcontroller.HttpServer( { "default":httpcontroller.StaticHandler }); //the default controller to use for all requests not handled by other controllers
server.start();
Put your site content in a sub-directory called "site". Eg.: "site/index.html" (by default index.html can be accessed without declaring the file in the url).
To test this code open the browser at http://localhost/

Controllers

const httpcontroller = require('httpcontroller');

class Api extends httpcontroller.Controller {
    /* http://localhost/Api/SomeData  */
    SomeDataGET() { 
        this.JsonResponse({ data: "some data"});
    }

    /* http://localhost/Api/AnotherData */
    AnotherDataGET(){
        this.JsonResponse({ data: "some other data"});
    }
}

const server = new httpcontroller.HttpServer({ Api });
server.start();

About

A node.js http server based on ASP.NET MVC

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published