Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future plans #3

Open
blaumeise20 opened this issue Apr 15, 2021 · 0 comments
Open

Future plans #3

blaumeise20 opened this issue Apr 15, 2021 · 0 comments

Comments

@blaumeise20
Copy link
Owner

blaumeise20 commented Apr 15, 2021

This issue is to track all plans this package has for the future.

Improved response components

Currently there is only one "response type" that is HtmlPage. It would be cool to have multiple other options:

  • JsonResponse - You can already think what it should do. It takes a JavaScript object and responses with the stringified version including correct headers.
    const Users: ElementGenerator = () => {
        // do some calculation
        return <JsonResponse data={result} />;
    };
    
    const api = express.Router();
    api.get("/users", createHandler(Users));
  • Static - The name says the thing. You specify the local path and it will respond with the correct data.
    const Logo: ElementGenerator = () => {
        // do some calculation
        return <Static path="./static/logo.png" />;
    };
    
    app.get("/logo.png", createHandler(Logo));

Actual router creation

You should be able to make express routers using special components:

const News: ElementGenerator = () => {
    return <div></div>;
};
const Routes: ElementGenerator = () => {
    return <Router>
        <Route path="/">
            For static content use children of route.
            <img src="logo.png" />
        </Route>
        <Route path="/logo.png">
            <Static path="./static/logo.png" />
        </Route>
        <Route path="/news" content={News} />
    </Router>;
    // and much more
};
app.use(createRouter(Routes));

Better request handling function

When using a HtmlPage with a response status without declaring a component it won't work. Look at this example:

app.all("*", (req, res) => {
    // won't work
    res.send(render(<HtmlPage status={404}>
        ERROR<br />
        This page doesn't exist.
    </HtmlPage>));
});

Instead there should be a handle function returned by the create function used like this:

app.all("*", (req, res) => {
    // will work
    handle(req, res, <HtmlPage status={404}>
        ERROR<br />
        This page doesn't exist.
    </HtmlPage>);
});

IMPORTANT: HTML entities

Currently, when you set an attribute to a string that contains a quote, it will just output it like that and the HTML will be incorrect.

const testAttr = "hello \"world\"";
render(<div test={testAttr}></div>);
// <div test="hello "world""></div>

We should take care of that.


If you have any other idea just comment on this issue.

@blaumeise20 blaumeise20 pinned this issue Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant