Grunt HTTP Static Server

2.1.0 · abandoned · verified Sun Apr 19

grunt-http-server is a Grunt task designed to serve static files from within a Grunt build process. It allows developers to quickly set up a local HTTP or HTTPS server for development and testing purposes. The package, currently at version 2.1.0 (last published in 2015), offers features such as serving files from a specified root directory, configurable ports and hosts, caching, directory listing, automatic index file serving, custom file extensions, and a proxying capability for requests not resolved locally. It also supports HTTPS with custom certificates and allows opening a browser automatically. Its primary differentiation lies in its integration with the Grunt ecosystem, providing a task-based approach to running a simple web server, unlike modern standalone CLI tools or bundler-specific development servers. The project has not seen updates since 2016, indicating it is no longer actively maintained.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure and run a basic static HTTP server using `grunt-http-server` within a Gruntfile, serving files from a 'dist' directory, enabling HTTPS, and opening a browser automatically.

module.exports = function(grunt) {

    grunt.initConfig({
        'http-server': {
            'dev': {
                // the server root directory
                root: 'dist', // Assume 'dist' is your build output folder

                // the server port
                port: 8282,

                // the host ip address
                host: '0.0.0.0',

                cache: 0, // No caching for dev
                showDir: true,
                autoIndex: true,
                ext: 'html',
                runInBackground: false,
                logFn: function(req, res, error) {},
                // proxy: 'http://someurl.com',
                https: {
                    cert: 'path/to/cert.pem', // Replace with your actual cert path
                    key : 'path/to/key.pem'   // Replace with your actual key path
                },
                openBrowser : true,
                customPages: {
                    '/readme': 'README.md'
                }
            }
        }
    });

    // Load the plugin that provides the 'http-server' task.
    grunt.loadNpmTasks('grunt-http-server');

    // Default task.
    grunt.registerTask('default', ['http-server:dev']);
};

view raw JSON →