Pkg: 404 on each API request!

Created on 22 May 2017  路  5Comments  路  Source: vercel/pkg

I have created the Linux file and when I run it using ./filename-linux command.

The server gets started but all the requests sent to the server are 404.

Whereas when I use normal command node server.js server starts and all requests gets 200 or 400 or whatever!

Any help would be much appreciated

Most helpful comment

Any code would be appreciated as well!

All 5 comments

Any code would be appreciated as well!

What code are you talking about?

The code of your application, particularly server.js

var dotenv = require('dotenv').config();
/**

  • This the main entry file for the app.
    */

var Express = require('express'),
BodyParser = require('body-parser'),
Passport = require('passport'),
Mongoose = require('mongoose'),
Morgan = require('morgan'),
JWT = require('jsonwebtoken'),
secrets = require('./config/secrets'),
apiHandler = require('./services/api-handler'),
appConfig = require('./config/config'),
authToken = require('./models/auth-token'),
cors = require('cors');

// Setup database
Mongoose.Promise = global.Promise;
Mongoose.connect('mongodb://' + process.env.DB_HOST + '/' + process.env.DB_NAME);
Mongoose.connection;

// Init App
var App = Express();

// Cross origin
App.use(cors());

App.use(process.env.PROFILE_UPLOAD, Express.static('profileUploads'));

// To allow browser hit the url and download file
App.use(process.env.CSV_UPLOAD, Express.static('csv'));

// BodyParser middleware
// Create application/json parser
App.use(BodyParser.json({ limit: '50mb' })); // Set request size

// create application/x-www-form-urlencoded parser
App.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));

// Passport init
App.use(Passport.initialize());
App.use(Passport.session());

// Creates server logs
App.use(Morgan('dev'));

// Token Interceptor
App.use(function (req, res, next) {
var excludedRoutes = appConfig.excludedRoutes, token;

if (excludedRoutes.indexOf(req.path) === -1) {
    token = req.headers.token || req.body.token || req.headers['x-access-token'];
    if (token) {
        authToken.getUserByToken(token, function (err, tokenUser) {
            if (err || !tokenUser) {
                apiHandler.setErrorResponse('TOKEN_EXPIRED', res);
            } else {
                JWT.verify(token, secrets.jwtSecret, function (err, decoded) {
                    if (err) {
                        apiHandler.setErrorResponse('INVALID_TOKEN', res);
                    } else {
                        req.decoded = decoded;
                        req.user = tokenUser.user;
                        next();
                    }
                });
            }
        });
    } else {
        apiHandler.setErrorResponse('NO_TOKEN', res);
    }
} else {
    next();
}

});

// Use the custom routes
require('./routes/index')(App);

// Set port
App.set('port', (process.env.PORT));
App.set('host', (process.env.HOST));

App.listen(App.get('port'), function () {
console.log('Server started at ' + App.get('host') + ':' + App.get('port'));
});

Any chance of a smaller snippet? :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jflayhart picture jflayhart  路  4Comments

erikd picture erikd  路  3Comments

j-brown picture j-brown  路  4Comments

Nisthar picture Nisthar  路  4Comments

ksmithut picture ksmithut  路  4Comments