Antinode is a simple static file webserver built on node.js.

Usage

Run it from the command line.

$ node server.js [settings.json]

Requires Node.JS v0.1.100 or greater. If you want to bind to a port under 1024, you'll need to run node with special privileges.

Configuration

Configuration is through a JSON text file, by default the settings.json in the same folder as server.js.

Example settings file:

{
    "port" : 8080,
    "hosts" : {
        "subdomain1.example.com" : { 
            "root" : "/www/subdomain1/"
        },
        "subdomain2.example.com" : {
            "root" : "/www/subdomain2/"
        }
        },
    "default_host" : {
        "root" : "/www/default/"
    }
}

This server listens on port 8080 for HTTP requests. If it gets a request for Host: subdomain1.example.com the site will serve /www/subdomain1/, and similarly requests for Host: subdomain2.example.com will respond with the files from /www/subdomain2. If the Host header does not match either, or is not given, antinode will serve files from /www/default.

Explanation of properties:

  • port - the port to listen for HTTP connections on. default: 8080
  • hosts - an object with one property name per virtual host address, with the value of a 'virtual host' object to
  • default_host - the 'virtual host' object to default to if no other virtual hosts match, or the HTTP Host header is not given

'virtual host object' - has a property root giving the directory to serve web requests from

This serves up all the files in /var/www listening to HTTP requests on port 8080. E.g. an HTTP request for /styles/site.css will will look for the file /var/www/styles/site.css

Features

  • HTTP Content-Type header detection from file extension
  • HTTP Content-Length header support
  • HTTP Date header
  • HTTP Last-Modified header
  • Reads files in binary mode - so can serve images and other binary files (not just text)
  • Requests to any directory try to return directory/index.html
  • Virtual Hosts

Test Suite

To run the tests:

$ node runtests.js

Credits

Original code forked from Noah Sloan's simple logging webserver.



Antinode是一个基于node.js的简单静态文件webserver。

Usage

从命令行运行

$ node server.js [settings.json]

需要Node.JS v0.1.100或更高版本。 如果要绑定到1024以下的端口,则需要运行特殊节点 权限。

Configuration

配置是通过一个JSON文本文件,默认情况下, settings.json server.js 相同的文件夹。

示例设置文件:

{
    "port" : 8080,
    "hosts" : {
        "subdomain1.example.com" : { 
            "root" : "/www/subdomain1/"
        },
        "subdomain2.example.com" : {
            "root" : "/www/subdomain2/"
        }
        },
    "default_host" : {
        "root" : "/www/default/"
    }
}

此服务器侦听端口8080的HTTP请求。 如果要获取 Host:subdomain1.example.com 的请求,则网站将投放 / www / subdomain1 / ,同样请求 Host:subdomain2.example.com 将使用 / www / subdomain2 中的文件进行响应。如果 Host 头 不匹配,或不给,antinode将提供文件 / www / default

属性说明

  • port - 用于监听HTTP连接的端口。默认值:8080
  • hosts - 每个虚拟主机地址具有一个属性名称的对象,virtual host对象的值为
  • default_host - 如果没有其他虚拟主机匹配,则默认为虚拟主机对象,或未指定HTTP Host

'虚拟主机对象' - 具有赋予目录服务的属性 root 来自

的网络请求

这将提供 / var / www 中侦听端口8080上的HTTP请求的所有文件。 例如。 /styles/site.css 的HTTP请求将会查找文件 /var/www/styles/site.css

Features

  • HTTP Content-Type 从文件扩展名
  • 检测头文件
  • HTTP Content-Length 标头支持
  • HTTP 日期标题
  • HTTP Last-Modified 标头
  • 以二进制模式读取文件 - 因此可以提供图像和其他二进制文件(而不仅仅是文本)
  • 请求任何目录尝试返回 directory / index.html
  • 虚拟主机

Test Suite

运行测试:

$ node runtests.js

Credits

诺亚·斯隆的原始代码简单日志网页服务器




相关问题推荐