Wednesday, 12 April 2017

Express server not serving my bundle.js

I'm trying to serve a bundle.js file from my React components but am unsure why the file isn't being served. I'm using Express and have a project with these files:

project
    /dist
        bundle.js
    /views
       /home
          index.ejs
    /routes
       index.js
    app.js

In my app.js, I tried to serve bundle.js:

DIST_DIR = path.join(__dirname, 'dist')
app.use(express.static(DIST_DIR));

My simple views/home/index.ejs looks like:

<!DOCTYPE html>
<html>

<head>
  <title></title>
  <link rel='stylesheet' href='css/styles.css'/>
</head>

<body id="main-page">
    <div class="container">
    </div>
  <script src="index.js"></script>
</body>

</html>

I finally GET the page in my routes/index.js using:

router.get('/', function(req, res, next) {
     res.render('home/index.ejs');
});

But I come back with an error: empty response whenever I try to load the page. I'm missing something and am unsure where. Any help would be appreciated.



via user7050542

No comments:

Post a Comment