2.4.0 • Published 5 years ago

easy-server v2.4.0

Weekly downloads
111
License
ISC
Repository
github
Last release
5 years ago

#Easy server

Really lightweight wrapper around express to help you make a neat app from day one

##Options

{
    "controllers": "./controllers", // folder containing your controller files
    "middleware": "./middleware", // folder containing your middleware files
    "autoStart": true, // if set to false, you need to call setup()
    "debug": Function, // pass a function to be used as the debug logger
    "cluster": Number, // optional - leaving out will run 1 instance of express
    "extensions": [".js", ".jsx"], // optional - defaults to [".js"]
}

All files in controllers and middleware directories will be included automatically, except for files and folders starting with _.

Tip: Use easy-server-dev in your development environment to get controllers to hot-reload when they change.

##Example app

server.js
|  - app/
|  |  - controllers/
|  |  |  - account.js
|  |  - middleware/
|  |  |  - auth.js
// server.js
var server = new Server({
    controllers: "./app/controllers",
    middleware: "./app/middleware",
    autoStart: false,
    debug: console.log,
    cluster: 4
});
server.use(require('cookie-parser'));
server.start();
// app/controllers/account.js
module.exports = {
    controller: function(app) {
        app.get('/account', app.middleware.get('auth'), function(req, res) {
            res.send('Welcome to your account');
        });
    }
};
// app/middleware/auth.js
module.exports = function(req, res, next) {
    if(!req.cookies['auth']) {
        return res.status(401).send('Unauthorized');
    }

    next();
};
2.4.0

5 years ago

2.3.4

7 years ago

2.3.2

8 years ago

2.3.1

8 years ago

2.2.0

8 years ago

2.1.0

9 years ago

2.0.8

9 years ago

2.0.7

9 years ago

2.0.6

9 years ago

2.0.5

9 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.4.0

9 years ago

1.3.0

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago