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

Error : Cannot GET / #315

Open
Aadriya opened this issue Apr 17, 2017 · 3 comments
Open

Error : Cannot GET / #315

Aadriya opened this issue Apr 17, 2017 · 3 comments

Comments

@Aadriya
Copy link

Aadriya commented Apr 17, 2017

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

@marshall86
Copy link

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

@Aadriya
Copy link
Author

Aadriya commented Apr 22, 2017

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

@yuyic
Copy link

yuyic commented Jun 14, 2017

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants