Home / Function/ stylesFromServer() — astro Function Reference

stylesFromServer() — astro Function Reference

Architecture documentation for the stylesFromServer() function in css-inline-stylesheets.test.js from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  5f52f67d_ebb0_7474_c14f_fe4574dd56b8["stylesFromServer()"]
  69f44a61_9817_7df2_a252_265cbb82c7d7["css-inline-stylesheets.test.js"]
  5f52f67d_ebb0_7474_c14f_fe4574dd56b8 -->|defined in| 69f44a61_9817_7df2_a252_265cbb82c7d7
  style 5f52f67d_ebb0_7474_c14f_fe4574dd56b8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/test/css-inline-stylesheets.test.js lines 273–294

async function stylesFromServer(app) {
	const request = new Request('http://example.com/');
	const response = await app.render(request);
	const html = await response.text();
	const $ = cheerio.load(html);

	const links = $('link[rel=stylesheet]');
	const hrefs = links.map((_, linkEl) => linkEl.attribs.href).toArray();
	const allLinkedStylesheets = await Promise.all(
		hrefs.map(async (href) => {
			const cssRequest = new Request(`http://example.com${href}`);
			const cssResponse = await app.render(cssRequest);
			return await cssResponse.text();
		}),
	);
	const allLinkedStyles = allLinkedStylesheets.join('');

	const styles = $('style');
	const allInlinedStylesheets = styles.map((_, styleEl) => styleEl.children[0].data).toArray();
	const allInlinedStyles = allInlinedStylesheets.join('');
	return allLinkedStyles + allInlinedStyles;
}

Subdomains

Frequently Asked Questions

What does stylesFromServer() do?
stylesFromServer() is a function in the astro codebase, defined in packages/astro/test/css-inline-stylesheets.test.js.
Where is stylesFromServer() defined?
stylesFromServer() is defined in packages/astro/test/css-inline-stylesheets.test.js at line 273.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free