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

164
Visualizações
Gotta conflict with... itself in express

I've integrated for my bot APIs. I expected they will work very well, but the truth is no...
I still can't figure out how the server gonna abort itself... This is error output, and the code, screenshot. Just help me...

Error: Request aborted

    at onaborted (/home/runner/TModeration-Server/node_modules/express/lib/response.js:1052:15)
    at Immediate._onImmediate (/home/runner/TModeration-Server/node_modules/express/lib/response.js:1094:9) {
  code: 'ECONNABORTED'
}
// API server
const express = require('express')
const path = require("path")
const app = express()
const PORT = 443

app.get('/api/', (req, res) => {
  var options = {
    root: path.join(__dirname)
  };
  res.writeHead(200, {'Content-Type': 'text/plain'})
  const requiredFile = req.path.toLowerCase.replaceAll('https://', '').replaceAll('tmoderation-server.henry133.repl.co', '').replaceAll('/api/', '')
  res.sendFile(`./APIs/${requiredFile ?? "index.js"}`, options, function(err) { console.log(err) })
  res.end()
})

app.get('/', (req, res) => {
  var options = {
    root: path.join(__dirname)
  };
  res.writeHead(200, {'Content-Type': 'text/html'})
  res.sendFile("./html.txt", options, function(err) { console.log(err) })
  res.end()
})

app.listen(PORT || 443, () => {
  console.log(`APIs [BETA] is listening ${PORT}`)
})

image

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you want to send a static file you can use sendFile method, try this syntax with path.resolve:

app.get('/', (req, res) => {
  res.status(200).sendFile(path.resolve('html.txt'));
})

about 4 years ago · Juan Pablo Isaza Relatório

0

I think this error occurs because the next middleware method is not called, try this syntax:

app.get('/', (req, res, next) => {
var options = {
    root: path.join(__dirname)
  };
  res.writeHead(200, {'Content-Type': 'text/html'})
  res.sendFile("./html.txt", options, function(err) { 
  if (err) {
        next(err);
    } else {
        console.log('Sent file');
        next();
    }
  })
  res.end()
})
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