Monday, 3 April 2017

Express and Apache - ENOENT on callback

I'm trying to run a React webapp I made on an Apache server using Express. The app is using routes on the front-end. It all seems to work well, except for my authentication library (Auth0) trying to make a call back to one of the front-end routes that throws a 404 with the following error:

Error: ENOENT: no such file or directory, stat '/dist/index.html'
at Error (native)

My virtual host entry is as follows:

    <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin admin@domain.com
        ServerName domain.com
        DocumentRoot /var/www/html/folder

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ProxyRequests Off
        ProxyPreserveHost On

        ProxyVia Full
        <Proxy *>
                Require all granted
        </Proxy>

        <Location /*>
                ProxyPass http://127.0.0.1:9000
                ProxyPassReverse http://127.0.0.1:9000
        </Location>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

<Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            # changed from None to FileInfo
            AllowOverride FileInfo
            Order allow,deny
            allow from all
    </Directory>

And this is my Express server:

    var express = require('express')
    var app = express()

    var path = require('path');

    app.use(express.static('dist'))

    app.get('*', function(req, res) {
      res.sendFile(path.resolve(__dirname, 'dist/index.html'));
    });

    app.listen(9000, function () {
      console.log('Example app listening on port 9000!')
    })

Not sure what I'm doing wrong. Anyone able to help?



via jcbmb

No comments:

Post a Comment