• Creates a middleware, that tries to get the current language from 'Accept-Language' HTTP header and writes it to 'lang' property of request context.

    Parameters

    • defaultLanguage: string

      The default language.

    • Rest ...additionalLanguages: string[]

      The list of additional, supported languages.

    Returns UniqueHttpMiddleware

    The new middleware.

    Example

    import assert from 'assert'
    import createServer, { IHttpRequest, IHttpResponse, lang } from '@egomobile/http-server'

    const app = createServer()

    // try submit 'Accept-Language' HTTP header
    // with 'de, en-GB;q=0.85, en;q=0.9'
    app.get('/', [lang('de', 'en')], async (request, response) => {
    assert.strictEqual(request.lang, 'de')
    })

Generated using TypeDoc