Stric
  • Basic
    • Intro
    • Routing
    • Serving files
    • Sending HTML
    • Quick response
    • CORS
    • Server-sent events
    • Clustering
  • Advance
    • How it works?
    • More
Powered by GitBook
On this page

Was this helpful?

  1. Basic

Sending HTML

Return HTML as a response

For convenient, @stricjs/utils provides the html method to send HTML response.

import { Router } from '@stricjs/router';
import { html } from '@stricjs/utils';

const page = `<html>
    <body>
        <h1>Hi</h1>
    <body>
</html>`;

export default new Router()
    .get('/', () => html(page));

If you want to add additional properties to the response init, create your own html function.

import { Router } from '@stricjs/router';
import { createHTML } from '@stricjs/utils';

const html = createHTML({ status: 404 });

const page = `<html>
    <body>
        <h1>Page not found</h1>
    <body>
</html>`;

export default new Router()
    .get('/404', () => html(page));

You can set the HTML content you want to send as well.

import { Router } from '@stricjs/router';
import { createHTML } from '@stricjs/utils';

// Call this with no args
const html = createHTML({ status: 404 }, `<html>
    <body>
        <h1>Page not found</h1>
    <body>
</html>`);

export default new Router()
    .get('/404', html);

Last updated 1 year ago

Was this helpful?