Node.js (Express) Restful API App in Cpanel not working(APIs)? getting 503 Service Unavailable

Viewed 1663

In this case I have mention auth API, other APIs also not working getting same results

In localhost it's working(server.use('/auth', routeAuth);)

In server once I created Node app in Cpanel(server.use('/server/auth', routeAuth);) which is not working

In server code block below server.js

const express = require('express');
const server = express();
const cors = require('cors');

const routeAuth = require('./auth/auth');
const routeRegister = require('./auth/register');

const routeArticle = require('./api/article/article');

const PORT = process.env.PORT || 4300;

server.use(express.json());
server.use(express.urlencoded({ extended: false}));
server.use(cors());

server.use('/server/auth', routeAuth);
server.use('/server/', routeRegister);

server.use('/server/api', routeArticle);

server.listen(PORT, () => console.log(`Server started on port: ${PORT}`));

localhost Postman test working enter image description here

After deploy to server and the result not working enter image description here

1 Answers

It happened because I had an DB configuration error, solved it with instead of using tempCont.release(); I omit it and used only the response, by doing this I have solve the error - TypeError: Cannot read property 'release' of undefined, which caused 503 Service Unavailable. Then after solving DB configuration issue I have again added the tempCont.release(); now it works fine.

router.post('/login', (req, res) => {
connection.getConnection((error, tempCont) => {
    if (error) {
        // tempCont.release();
        res.json({ message: 'Can not connect database' });
    }
    else { ....
Related