🦄 0-legacy, tiny & fast web framework as a replacement of Express
Full Changelog: https://github.com/tinyhttp/tinyhttp/compare/@tinyhttp/[email protected]...@tinyhttp/[email protected]
by @talentlessguy in https://github.com/tinyhttp/tinyhttp/pull/401
View engine was ported from express for cases like multiple view engines and custom View
processing. See docs for more info.
App
doesn't require a first argument as engine options in a generic anymore. Instead pass engine options to app.engine
and res.render
.
Example:
import { App } from '@tinyhttp/app'
import { renderFile, type EtaConfig } from 'eta'
import type { PartialConfig } from 'eta/dist/types/config'
const app = new App()
app.engine('eta', eta.renderFile)
app.use((_, res) => void res.render<PartialConfig>('index.eta', { name: 'Eta' }))
app.listen(3000, () => console.log(`Listening on http://localhost:3000`))
AppConstructor
A constructor type for @tinyhttp/app
has been moved into a type for more convenience:
import type { AppConstructor } from '@tinyhttp/app'
app.disabled
Returns if a setting is disabled:
app.disabled('networkExtensions') // true
req.xhr
from a header by @aarontravass in https://github.com/tinyhttp/tinyhttp/pull/408
req.route
us assigned the correct middleware if multiple are present by @aarontravass in https://github.com/tinyhttp/tinyhttp/pull/409
@tinyhttp/app
from 25 to 23.@tinyhttp/app
decreased from 692KB to 540KB (22% smaller) by switching from es-mime-types
to mime@beta
app.set
, app.enable
and app.disable
now have stricter typesapp.engine
supports extensions with and without a dotapp.render
, res.render
and app.engine
support passing template engine options as a generices-
modules owned by @talentlessguy are moved to the tinyhttp organization to avoid lock-in and make it easier to maintainFull Changelog: https://github.com/tinyhttp/tinyhttp/compare/@tinyhttp/[email protected]...@tinyhttp/[email protected]
Full Changelog: https://github.com/tinyhttp/tinyhttp/compare/@tinyhttp/[email protected]...@tinyhttp/[email protected]
tinyhttp finally drops all CommonJS outputs and becomes pure ESM. Node.js 10 became EOL so this means all LTS versions starting v12 support the framework. All of the middlewares are also pure ESM now.
freshnessTesting
property because it makes no sensethanks to @wasd845, @tbhmens, @fabiospampinato, @sbencoding, @e965, @n1ru4l, @paolotiu, @eltociear, @sonnyp, @aral, @wakeupmh, @aldy505, @massivefermion for helping with the project! ❤️❤️❤️
acceptsLanguages
method in Request
interfaceRange
header support for sendFile
Content-Encoding
and Last-Modified
headers for sendFile
.add(...)
methodsendFile
req.signedCookies
to {}
req.fresh
not getting setHEAD
not being set implicitly (https://github.com/talentlessguy/tinyhttp/issues/243)xPoweredBy
setting (3ff78610646ab3c58451f900ea0bf6a3c54acfc0)url.parse
in favor of a custom func (9a5573fb7fd724d52217745c839d81bacb3f90f9)mutate
function in app.handle
(d533d2cbac50d93e6f88b0cc738e90fe1fbb2125)For example:
tinyhttp new prisma-graphql my-new-project --prettier --eslint
Example from README:
import { App } from 'https://deno.land/x/[email protected]/app.ts'
const app = new App()
app.use('/', (req, next) => {
console.log(`${req.method} ${req.url}`)
next()
})
app.get('/:name/', (req) => {
req.respond({ body: `Hello ${req.params.name}!` })
})
app.listen(3000, () => console.log(`Started on :3000`))
@tinyhttp/logger
: no longer depend on core (01265c002d18a06e210f45bf5cb3a82f4e86d51a)@tinyhttp/cors
: support a range of origins and regex (6502fcc56b05d6112c615f2af514dab0aa3ec248)@tinyhttp/cors
: preflightContinue
setting (c1cd15a21964c021e831d95eb936c7ced224fba8)@tinyhttp/cors
: Fix 404 on OPTIONS in (263dd95215136f0717d9016bdf371f7747afb7a3)req.range
(de0ea5503c7b50907d99598b831bed5d69e6f31e)res.sendFile
(de0ea5503c7b50907d99598b831bed5d69e6f31e)res.cookie
not appending headers (bd5ca65c94c4a3a47ab8d36f58070148425aaf81)value
argument optional for res.set
and res.header
(b06d8d5da933b86fd64e4b7afdca5f24cb02f1cb)req.url
, req.path
and req.originaUrl
(#203)res.redirect
incorrect URI encoding (#205)res.set
(and extensions using it) not adding charsetres.render
not inheriting template engine settings@tinyhttp/markdown
now sends a stream instead of plain text using streamdown
@tinyhttp/markdown
doesn't have recursive
option anymore. Instead of file listing, the current directory is switched in case the path contains a directory. Therefore, the ware no longer depends on readdirp
@tinyhttp/markdown
now has a caching
setting to configure Cache-Control
header@tinyhttp/session
now uses express-session
as direct dependency instead of dev (#201)Finally, after months of hard work, different implementation decisions, collaborations with contributors I'm thrilled to announce the first stable release of tinyhttp!
100% ready. The only method that isn't implemented is app.param
, which was deprecated in Express 4.11.
errors thrown in async handlers are now catched and passed to next
, e.g. if an error is throwed in a handler it won't crash and will keep working.
Example:
import { App } from '@tinyhttp/app'
const app = new App()
app.use(async (_req, _res) => {
throw `error`
})
app.listen(3000)
The app will return the error and send 500 status:
$ curl localhost:3000
error
WIth the new applyExtensions
parameter you can define your own req
/ res
extensions, or disable all tinyhttp's extensions to achieve the best performance.
import { App } from '@tinyhttp/app'
import { send } from '@tinyhttp/send'
const app = new App({
applyExtensions: (req, res, next) => {
// now tinyhttp only has a `res.send` extension
res.send = send(req, res)
}
})
IncomingMessage
and ServerResponse
objects but only the properties which are used inside the module. This will let developers use these packages inside their own projects and not only in Node.js runtime.