# express-autoserve

> Automatically support different Express app deployment strategies such as FastCGI, Passenger, and node http.

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

## Install

```sh
npm install express-autoserve
pnpm add express-autoserve
yarn add express-autoserve
bun add express-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.2 |
| Published | 2016-09-28 |
| First published | 2016-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | binki |

## Links

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

## Dependencies (2)

- [express](https://npm.io/package/express.md) ~4
- [autoserve](https://npm.io/package/autoserve.md) ^0.0.3

## Recent versions

- 0.0.2 (latest) — 2016-09-28

## README

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

[Autodetect the service platform](https://github.com/binki/autoserve) and delegate to an
Express app.

# Usage

    const expressAutoserve = require('express-autoserve');
    const app = require('./app');
    
    expressAutoserve(app);

# Mechanics

## `req.baseUrl`

The node [`http`](https://nodejs.org/api/http.html) module has no
concept of `baseUrl` because it assumes it will get to open the TCP
socket itself and just serve out pages at `/`. However, various
deployment strategies supported by
[`autoserve`](https://github.com/binki/autoserve) are
commonly used to deploy applications at URIs other than `/`. Thus
`autoserve` provides a `getBaseUrl(req)` function to discover
the baseUrl for the current request (in FastCGI, the necessary
information is not available until a request is received).

Express supports mounting applications at sub-paths. To enable mounted
applications to generate absolute URIs to resources within the apps,
it provide the
[`req.baseUrl`](https://expressjs.com/en/4x/api.html#req.baseUrl)
property. This enables the following to work sensibly:

    const express = require('express');
    
    const app = express();
    
    const subApp = express();
    subApp.get('/asdf', function (req, res) {
       // When mounted, will get /subApp/foo
      res.send(`Another resource on this app is ${req.baseUrl}/foo`);
    });
    subApp.get('/foo', function (req, res) {
      res.send(`You found me!`);
    });
    
    app.use('/subApp', subApp);
    app.listen(3000);

This module ensures that the passed app is treated like it is mounted
in an express app at the `baseUrl` calculated by
`autoserve`. This causes the `baseUrl` to be set properly for
the passed app and ensures that routing is performed relative to the
deployment `baseUrl`.

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