简体   繁体   中英

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

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在此处输入图像描述

After deploy to server and the result not working在此处输入图像描述

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 { ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM