url-rewriting.test.js — fastify Source File
Architecture documentation for url-rewriting.test.js, a javascript file in the fastify codebase.
Entity Profile
Source Code
'use strict'
const { test } = require('node:test')
const Fastify = require('..')
test('Should rewrite url', async t => {
t.plan(4)
const fastify = Fastify({
rewriteUrl (req) {
t.assert.strictEqual(req.url, '/this-would-404-without-url-rewrite')
this.log.info('rewriting url')
return '/'
}
})
fastify.route({
method: 'GET',
url: '/',
handler: (req, reply) => {
reply.send({ hello: 'world' })
}
})
const fastifyServer = await fastify.listen({ port: 0 })
t.after(() => fastify.close())
const result = await fetch(`${fastifyServer}/this-would-404-without-url-rewrite`)
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 200)
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
})
test('Should not rewrite if the url is the same', async t => {
t.plan(3)
const fastify = Fastify({
rewriteUrl (req) {
t.assert.strictEqual(req.url, '/this-would-404-without-url-rewrite')
this.log.info('rewriting url')
return req.url
}
})
fastify.route({
method: 'GET',
url: '/',
handler: (req, reply) => {
reply.send({ hello: 'world' })
}
})
const fastifyServer = await fastify.listen({ port: 0 })
t.after(() => fastify.close())
const result = await fetch(`${fastifyServer}/this-would-404-without-url-rewrite`)
t.assert.ok(!result.ok)
t.assert.strictEqual(result.status, 404)
// ... (63 more lines)
Source
Frequently Asked Questions
What does url-rewriting.test.js do?
url-rewriting.test.js is a source file in the fastify codebase, written in javascript.
Where is url-rewriting.test.js in the architecture?
url-rewriting.test.js is located at test/url-rewriting.test.js (directory: test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free