# autoserve

> Support deployment via FastCGI, Passenger, or node http.

Latest version **0.0.3** (published 2016-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install autoserve
pnpm add autoserve
yarn add autoserve
bun add autoserve
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-09-28 |
| First published | 2016-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | binki |

## Links

- npm: https://www.npmjs.com/package/autoserve
- Repository: https://github.com/binki/autoserve
- Homepage: https://github.com/binki/autoserve#readme
- Issues: https://github.com/binki/autoserve/issues
- npm.io page: https://npm.io/package/autoserve

## Dependencies (1)

- [node-fastcgi](https://npm.io/package/node-fastcgi.md) ~1 >=1.3.0

## Recent versions

- 0.0.3 (latest) — 2016-09-28

## README

This is being renamed to [`autoserve`](https://npmjs.com/package/autoserve).

Enable a webapp to get the optimal `http` implementation based on how
it is deployed. Also provide a way to get the `baseUrl` of the
deployment.

Ways one might deploy a node-based webapp:

* [http](https://nodejs.org/api/http.html)
* [node-fastcgi](https://github.com/fbbdev/node-fastcgi)
* CGI (in the future just as proof of concept, please don’t use in production)
* Passenger

# Usage

`script.cgi`:

    #!/usr/bin/env node
    'use strict';
    
    const httpAutodetect = require('http-autodetect');
    
    const app = function (req, res) {
        res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8', });
        // It is recommended to use a framework like express to calculate
        // the host and protocol of your deployment. getBaseUrl() only
        // solves the path portion of the deployment.
        res.end(`Hello, World! I am deployed at https://${req.headers.host}${httpAutodetect.getBaseUrl(req)}`);
    };
    
    httpAutodetect(app);

## Express Usage

You need extra middleware to get Express to respect
`getBaseUrl()`. See
[express-http-autodetect](https://github.com/binki/express-http-autodetect)
for that or use this snippet:

    #!/usr/bin/env node
    'use strict';
    const expressHttpAutodetect = require('express-http-autodetect');
    
    // If you followed the Express-4 migration guide or used
    // express-generator, your app definition will be its own
    // CommonJS module.
    const app = require('./app');
    
    expressHttpAutodetect(app);

Note the Connect is not supported as it does not have the concept of
managing `baseUrl`/mounting sub-apps. It only chains handlers and is
missing the sort of routing handling that proper `baseUrl` handling
requires.

---
_Source: https://npm.io/package/autoserve · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
