summaryrefslogtreecommitdiff
path: root/packages/astro/test/fixtures/middleware space/integration-middleware-post.js
blob: cb1855d481e01fcfe745ab879301a82d5246edde (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { defineMiddleware } from 'astro:middleware';

export const onRequest = defineMiddleware((context, next) => {
	if (context.url.pathname === '/integration-post') {
		return new Response(JSON.stringify({ post: 'works' }), {
			headers: {
				'content-type': 'application/json',
			},
		});
	}
	
	if (context.url.pathname === '/does-not-exist') {
		return context.rewrite('/rewrite');
	}

	return next();
});