0.5.14 • Published 9 years ago

easy-express v0.5.14

Weekly downloads
4
License
BSD-2-Clause
Repository
github
Last release
9 years ago

What

Express with sockets (+sessions), session, file server (for yeoman fast debug), rpc: with just 1* line; Works out of the box

Install

npm install easy-express

Setup

  • MongoDB: Run "mongod" in order to use the mongodb database. Is required in order to work (for now).
  • Node

Use

Create a file named "index.js" with the following contents. Then run it like this "node index.js".

var defaultOptions = {

    /**
     * The type of environment. Based on this, if yeoman is enabled,
     * will add certain file paths to the server.
     * [development, production]
     *
     * You can also manually set certain file paths for each environment.
     */
    environment: 'development',

    /**
     * Sometimes you just want to start your node in a certain environment
     * just by appending on of the keywords ['production', 'development'].
     * This will override the environment passed in environment.
     *
     * @todo: should be better and should not only be in the index = 2.
     *
     * Set this value processArgv equal to the process.argv.
     *
     *     {
     *         extractEnvironmentFromCmdLineOptions : true,
     *         processArgv                          : process.argv
     *     }
     */
    extractEnvironmentFromCmdLineOptions: null,

    /**
     * Pass the process argv. Those are only used if
     * extractEnvironmentFromCmdLineOptions is true.
     */
    processArgv: null,


    /**
     * Host name
     */
    host: 'localhost',

    /**
     * Port of the host
     */
    port: 80,

    /**
     * Sockets
     */
    sockets: {
        enabled: true,

        /**
         * Url of the socket used in socket.io
         */
        url: '/socket',

        /**
         * Log level of the sockets.
         */
        logLevel: 1,
    },
    ssl: {
        enabled: false,
        key: null,
        cert: null,
        port: 443,
    },
    /**
     * Sessions
     */
    sessions: {
        enabled: true,

        /**
         * Type of session:
         *  - database: saves to a mongodb database by default
         *  - memory: saves in memory, bad practice and doesn't work with sockets
         */
        type: 'database',

        /**
         * The secret that encodes the sessions. (change this)
         */
        secret: 'random',

        /**
         * For how long lasts the sessions in milliseconds.
         */
        maxAge: 9000000,

        /**
         * Database of the sessions, when database is enabled.
         */
        database: {

            /**
             * Where the sessions are saved.
             */
            name: 'sessions',

            /**
             * Database host.
             */
            host: 'localhost',

            /**
             * Database port.
             */
            port: 27017,
        },
    },

    /**
     * Compress files for faster downloading.
     */
    enableGzip: true,

    /**
     * Used to get the post data in the requests.
     */
    enableBodyParser: true,

    /**
     * Serve files from path. Is recommend to be only used in a development
     * environment. In production use nginx, is faster and better.
     *
     * serveIndexByDefault:
     *     Whenever you want to serve the index.html from the static folder.
     *     Turn off when you want your express route to catch the "/" route
     *     and serve a specific html file or a dynamic one.
     *
     * Format:
     *     {
     *         path: 'my/path',
     *         serveIndexByDefault: false // Default true
     *     }
     */
    fileServer: {
        paths: []
    },

    /**
     * Enabling yeoman will add (not replace) your file server based on the environment.
     * If the environment is development will add 2 paths and in that order:
     *     /.tmp
     *     /app
     * If is production:
     *     /dist
     */
    yeoman: {
        enabled: true,

        /**
         * Root folder of the server, used to create a file server for
         * files in the .tmp, app and dist folder.
         */
        rootFolder: null,

        /**
         * Apply serveIndexByDefault to each yeoman folder.
         * Read fileServer for more info.
         */
        serveIndexByDefault: true,
    },

    /**
     * Using this will force the app to be in a certain way which is:
     *  - You can communicate both via sockets and post seamless;
     *  - The post path is always "/rpc"
     *  - The socket event name is always "rpc"
     *  - Services are called using the API on the client side and has the following
     *    format:
     *        {
     *            serviceName: String
     *            serviceArguments: Whatever you want
     *        }
     *  - The output of the service has the following format:
     *        {
     *            id: Number, only used in sockets to know which socket is for which request,
     *            data: data returned by the service,
     *            err: [errorMessage:String, errorNumber: Integer]
     *        }
     *  - In the case of sockets when they are connected will return the following data:
     *        {
     *            data: {connected: true},
     *            err: undefined
     *        }
     */
    rpc: {
        enabled: true,

        /**
         * This is the rpc app; The service name will always be a method on the rpcApp;
         */
         app: null,
    },
}


var innerDefaults = {
    fileServer: {
        path: {
            url                 : '',
            serveIndexByDefault : true,
        }
    }
}
0.5.14

9 years ago

0.5.13

10 years ago

0.5.12

10 years ago

0.5.11

10 years ago

0.5.9

10 years ago

0.5.8

10 years ago

0.5.7

10 years ago

0.5.6

10 years ago

0.5.5

10 years ago

0.5.4

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.0

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.2.1

10 years ago

0.1.13

10 years ago

0.1.12

10 years ago

0.1.11

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago