Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@developit
CreatedSeptember 5, 2019 00:30
    • Star(16)You must be signed in to star a gist
    • Fork(3)You must be signed in to fork a gist
    Save developit/699c8d8f180a1e4eed58167f9c6711be to your computer and use it in GitHub Desktop.
    constexpress=require('express');
    const{ html, Component}=require('htm/preact');
    constrenderToString=require('preact-render-to-string');
    classAppextendsComponent{
    render(props){
    returnhtml`
    <divclass="app">
    <h1>This is an app</h1>
    <p>Current server time:${newDate+''}</p>
    </div>
    `;
    }
    }
    constapp=express();
    app.get('/',(request,response)=>{
    // render your app to an HTML string
    constbody=renderToString(html`<${App}url=${request.url}/>`);
    // wrap it in an HTML document and send it back
    response.send(`<!DOCTYPE html><html><body>${body}</body></html>`);
    });
    {
    "dependencies": {
    "htm":"^2.2.1",
    "preact":"^8.5.2",
    "express":"^4.17.1"
    }
    }
    @mxro
    Copy link

    mxro commentedDec 6, 2021

    Doesn't this also need the dependencypreact-render-to-string ?

    Copy link

    great example!

    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp