Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

301
Visualizações
Next.JS Cpanel Deployment Server.js not working properly

Im trying to deploy my website on cpanel. Im using node.js application with cpanel. see config:

enter image description here

but then i start my server it says "503 service unavailable".

enter image description here

when i try to edit my server.js file i see these weird errors.

enter image description here enter image description here enter image description here

server.js

const { createServer } = require("http");
const { parse } = require("url");
const next = require("next");

const dev = process.env.NODE_ENV !== "production";
const hostname = process.env.HOSTNAME || "localhost";
const port = process.env.PORT || 3000;
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();

app.prepare().then(() => {
  createServer(async function (req, res)  {
    try {
      // Be sure to pass `true` as the second argument to `url.parse`.
      // This tells it to parse the query portion of the URL.
      const parsedUrl = parse(req.url, true);
      const { pathname, query } = parsedUrl;
      await handle(req, res, parsedUrl);
    } catch (err) {
      console.error("Error occurred handling", req.url, err);
      res.statusCode = 500;
      res.end("internal server error");
    }
  }).listen(port, (err) => {
    if (err) throw err;
    console.log(`> Ready on http://${hostname}:${port}`);
  });
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

this might be better served as a comment and I apologise if it is but I'm unable to comment. I do however have something to contribute that may help move us towards an answer for this one.

I'm having a similar issue with my own application, what I have discovered is that however it's being interpreted by the server infrastructure what it wants is a semicolon after 'async'. This makes me wonder if perhaps in this kind of arena 'async' does something different to what we, the OP and I, are expecting it to, and how it typically operates on our local machines.

To Clarify, this block yields the same warning errors as OP mentions:

const register = async (req,res) => {
  const { username, email , password: Npassword, privilege} = req.body;
  if (!email || !Npassword || !username || !privilege)
    return res.json({ status: "error", error:"All Fields Required."});
  else {

However when the ';' is added after async those warning go away, it isn't a solution though as adding the semicolon there causes other warnings to pop up for the rest of the code:

const register = async; (req,res) => {
  const { username, email , password: Npassword, privilege} = req.body;
  if (!email || !Npassword || !username || !privilege) 
    return res.json({ status: "error", error:"All Fields Required."});
  else {

This is as much as I've been able to work out so far. As with OP my application runs perfectly fine on local machine and only has an issue when trying to deploy it on cpanel.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda