Saturday 17 December 2016

Express.js + React + ReactRouter :Unexpected token < error

So I've done some research in stackoverflow threads and found that it may the culprit:http://ift.tt/2hcnOOK, I am still having trouble getting rid of this error (perhaps I am not implementing correctly?)Here's my folder structure:Project | +-- dist | | | +-- bundle.js | +-- src | | | +-- client | | | ... holds my React Components, etc | index.js | | +-- server (run by express.js to hold server as API) | | | +-- controllers | +-- models | +-- services | -- index.js | -- router.js | +-- index.html | +-- webpack.config.js | | +-- babelrc | + So I've made the bundle.js available so that express can retrieve it via static file middlewaresrc/server/index.jsconst express = require('express'); const app = express(); const path = require('path'); const morgan = require('morgan'); const port = process.env.PORT || 1234; const bodyParser = require('body-parser'); const router = require('./router'); const mongoose = require('mongoose'); const db = process.env.MONGODB_URI || "http://mongodblocalhost:voteapp/voteapp"; const cors = require('cors') //DB Setup mongoose.connect(db); app.use(express.static(path.join(__dirname, '../../bundle.js'))) //App Setup app.use(morgan('combined')); app.use(cors()) //CORS middleware on express side app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })) router(app); //Server Setup(Express) app.listen(port,()=>{ console.log(`Server is listening on ${port}`) }) src/server/router.jsmodule.exports = function(app){ app.get('*', function(req, res) { res.sendFile(path.join(__dirname, '../../index.html')); }); app.get('/allpolls', AllPolls.allposts) app.get('/fetchvotes/:userName', FetchVotes.getvotes) app.post('/newpost', NewPost.newpost) app.get('/polls/:id', GetPoll.getpost) app.put('/polls/:id', CastVote.update) app.delete('/polls/:id', DeletePoll.deletepost) app.post('/signup', Authentication.signup) app.post('/signin', requireSignIn, Authentication.signin) } index.html
Here's the full detail of the repo in GithubWhat am I doing wrong?

Submitted December 17, 2016 at 04:22PM by KAMFlamenco

No comments:

Post a Comment