<commit_before># API

## Creating an app
```js
let aero = require('aero')
let app = aero()
```

## Routing
```js
app.get('/hello', (request, response) => {
	response.end('Hello!')
})
```

## Regex routing
```js
app.get(/^\+(.*)$/, (request, response) => {
	response.end('Google+ style routing')
})
```

## Middleware
```js
app.use(function(request, response, next) {
	console.log(request.url)
	next()
})
```

## Async middleware

```js
app.use(function*(request, response, next) {
	let start = new Date
	yield next()
	let ms = new Date - start

	console.log(request.url, ms + ' ms')
})
```

Not supported yet.

## Multiple 'use' with one call
```js
app.use(
	session(options),
	passport.initialize(),
	passport.session()
)
```

## Redirect
```js
app.redirect('/index.html', '/')
```

## Pre-Routing
```js
app.rewrite((request, response) => {
	// Handle /+MyName requests as /user/MyName internally
	if(request.url.startsWith('/+')) {
		request.url = '/user/' + request.url.substring('/+'.length)
		return
	}

	// Also rewrite ajax routes for the aero-ajax plugin
	if(request.url.startsWith('/_/+')) {
		request.url = '/_/user/' + request.url.substring('/_/+'.length)
		return
	}
})
```

## Redirect domains
```js
app.rewrite((request, response) => {<commit_msg>Added app.ready documentation<commit_after># API

## Creating an app
```js
let aero = require('aero')
let app = aero()
```

## Routing
```js
app.get('/hello', (request, response) => {
	response.end('Hello!')
})
```

## Regex routing
```js
app.get(/^\+(.*)$/, (request, response) => {
	response.end('Google+ style routing')
})
```

## Middleware
```js
app.use(function(request, response, next) {
	console.log(request.url)
	next()
})
```

## Async middleware

```js
app.use(function*(request, response, next) {
	let start = new Date
	yield next()
	let ms = new Date - start

	console.log(request.url, ms + ' ms')
})
```

Not supported yet.

## Multiple 'use' with one call
```js
app.use(
	session(options),
	passport.initialize(),
	passport.session()
)
```

## Ready

`app.run()` returns `app.ready` which is a promise that gets resolved when the server loaded all pages and started the server.

```js
app.run().then(() => {
    console.log('We are online!')
})
```

```js
app.ready.then(() => {
    console.log('We are online!')
})
```

## Redirect
```js
app.redirect('/index.html', '/')
```

## Pre-Routing
```js
app.rewrite((request, response) => {
	// Handle /+MyName requests as /user/MyName internally
	if(request.url.startsWith('/+')) {
		request.url = '/user/' + request.url.substring('/+'.length)
		return
	}

	// Also rewrite ajax routes for the aero-ajax plugin
	if(request.url.startsWith('/_/+')) {
		request.url = '/_/user/' + request.url.substring('/_/+'.length)
		return
	}
})
```

## Redirect domains
```js
app.rewrite((request, response) => {
{'fraction_non_alphanumeric': 0.21930447125621008, 'fraction_numerical': 0.0, 'mean_word_length': 4.007104795737122, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7165255', 'n_tokens_mistral': 1062, 'n_tokens_neox': 995, 'n_words': 239}