<commit_before>import express from 'express';
import React from 'react';
import { renderToString } from 'react-dom/server'
import { RouterContext , match } from 'react-router';
import appRoutes from './shared/routes'

const app = express();

app.use((req, res) => {
    let initialComponentHtml, isNotFoundPage = false;
    match({ routes: appRoutes(), location: req.url }, (error, redirectLocation, renderProps) => {
        if (error) {
            res.status(500).send(error.message);
        } else if (redirectLocation) {
            res.redirect(302, redirectLocation.pathname + redirectLocation.search);
        } else if (renderProps) {
            isNotFoundPage = !renderProps.routes;
            initialComponentHtml = renderToString(<RouterContext {...renderProps} />);
        }
    });
    const HTML = `
        <!DOCTYPE html>
        <html>
            <head>
                <meta charset="utf-8">
                <title>Universal Redux Demo</title>
            </head>
            <body>
                <div id="react-view">${initialComponentHtml}</div>
                <script type="application/javascript" src="/bundle.js"></script>
            </body>
        </html>`;
    res.status(isNotFoundPage ? 404 : 200).end(HTML);
});

export default app;<commit_msg>Fix not found page returning wrong status code<commit_after>import express from 'express';
import React from 'react';
import { renderToString } from 'react-dom/server'
import { RouterContext , match } from 'react-router';
import appRoutes from './shared/routes'

const app = express();

app.use((req, res) => {
    let initialComponentHtml, isNotFoundPage = false;
    match({ routes: appRoutes(), location: req.url }, (error, redirectLocation, renderProps) => {
        if (error) {
            res.status(500).send(error.message);
        } else if (redirectLocation) {
            res.redirect(302, redirectLocation.pathname + redirectLocation.search);
        } else if (renderProps) {
            isNotFoundPage = renderProps.routes[1].path === '*';
            initialComponentHtml = renderToString(<RouterContext {...renderProps} />);
        }
    });
    const HTML = `
        <!DOCTYPE html>
        <html>
            <head>
                <meta charset="utf-8">
                <title>Universal Redux Demo</title>
            </head>
            <body>
                <div id="react-view">${initialComponentHtml}</div>
                <script type="application/javascript" src="/bundle.js"></script>
            </body>
        </html>`;
    res.status(isNotFoundPage ? 404 : 200).send(HTML);
});

export default app;
{'fraction_non_alphanumeric': 0.13919694072657743, 'fraction_numerical': 0.010325047801147227, 'mean_word_length': 2.401820546163849, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3570358', 'n_tokens_mistral': 742, 'n_tokens_neox': 701, 'n_words': 168}