Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Error : Cannot GET / #315

Description

@Aadriya

When i run http://localhost:8080/ get Cannot GET /

Activity

  1. marshall86 commented on Apr 18, 2017

    @marshall86

    some issue, below my server.js file (I used require instead of import because it doesn't works for me)

    `var React = require('react');
    var express = require('express');
    var path = require('path');
    var compression = require('compression');
    var PORT = process.env.PORT || 1000;

    // we'll use this to render our app to an html string
    var ReactDOMServer = require('react-dom/server');

    // and these to match the url to routes and then render
    var match = require('react-router').match;
    var RouterContext = require('react-router').RouterContext;
    var routes = require('./app/modules/Routes');

    var app = express();

    app.use(compression());
    
    // serve our static stuff like index.css
    app.use(express.static(path.join(__dirname, 'app')));
    
    // send all requests to index.html so browserHistory works
    app.get('*', (req, res) => {
        match({ routes: routes, location: req.url }, (err, redirect, props) => {
            // in here we can make some decisions all at once
            if (err) {
                // there was an error somewhere during route matching
                res.status(500).send(err.message)
            } else if (redirect) {
                // we haven't talked about `onEnter` hooks on routes, but before a
                // route is entered, it can redirect. Here we handle on the server.
                res.redirect(redirect.pathname + redirect.search)
            } else if (props) {
                // if we got props then we matched a route and can render
                const appHtml = ReactDOMServer.renderToString(<RouterContext {...props} />);
    
                res.send(renderPage(appHtml))
            } else {
                // no errors, no redirect, we just didn't match anything
                res.status(404).send('Not Found')
            }
        })
    });
    
    app.listen(PORT, function() {
        console.log('Production Express server running at localhost:' + PORT);
    });
    

    function renderPage(appHtml) {
    return <!doctype html public="storage"> <html> <meta charset=utf-8/> <title>Antonio Scala Web Developer</title> <div id=app>${appHtml}</div> <script src="/bundle.js"></script>
    }`

    Besides I have this error:
    " const appHtml = ReactDOMServer.renderToString(<RouterContext {...props} />);
    ^
    SyntaxError: Unexpected token <"

    Any help? thanks

  2. Aadriya commented on Apr 22, 2017

    @Aadriya
    Author

    I think you use isomorphic method for serverside rendering (Isomorphic didnt support newest Version of react). Refer https://github.com/jackfranklin/universal-react-example ..this is a best example for Universal serverside rendering

  3. yuyic commented on Jun 14, 2017

    @yuyic

    I have this problem too. @Aadriya could you please explain more detail? what is isomorphic method? is this because the node version is too old?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions