Express route fires a second time

I have a program which I have reduced to almost nothing, and still get the problem that, if I include a HTML5 Video construct, then the initial route gets called twice.

app.js

var express = require('express');
var path = require('path');

var app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));

app.set('port', process.env.PORT || 4107);

app.get('/v/:vkey', function(req, res) {
  console.log('-------------- V -------');
  console.log(req.url);
  console.log(req.params);
  res.send('<!DOCTYPE html><html lang="en"><head><link href="/vendor/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"><script src="/vendor/bootstrap/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script></head><body><div id="vidguts"><div class="container-fluid"><div class="card mt-2"><div class="card-header"><h5>Video</h5></div><div class="card-body"><div class="row"><div class="col"><video controls="" width="100%" height="100%" autoplay=""><source src="beach0.mp4" type="video/mp4"></video></div></div></div></div></div></div></body></html>');
});
  
var server = app.listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

The html sent is (in PUG format to make it easy to read)

doctype html
html(lang="en")
  head
    link(href="/vendor/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet")
    script(src="/vendor/bootstrap/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous")

  body
    #vidguts
      .container-fluid
        .card.mt-2
          .card-header
            h5 Video
          .card-body
            .row
              .col
                video(controls width="100%" height="100%" autoplay="")
                  source(src="beach0.mp4" type="video/mp4")

Output:

Express server listening on port 4107
-------------- V -------
/v/13
{ vkey: '13' }
-------------- V -------
/v/beach0.mp4
{ vkey: 'beach0.mp4' }

So Express is somehow calling the ‘v’ route a 2nd time, with the vkey param being the ‘src’ attribute on the HTML5 Video construct. No video appears on the page, just a blank video screen (with the video controls, etc… but no actual video).

Node: v16.20.2
Express: v4.19.2

I call this test program using: localhost:4107/v/13

It’s just a common error with express when using params, it can be resolved by referencing the root path so it could fetch the video from public directory.

doctype html
html(lang="en")
  head
    link(href="/vendor/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet")
    script(src="/vendor/bootstrap/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous")

  body
    #vidguts
      .container-fluid
        .card.mt-2
          .card-header
            h5 Video
          .card-body
            .row
              .col
                video(controls width="100%" height="100%" autoplay="")
                  source(src="/beach0.mp4" type="video/mp4")

In app.js

app.get('/v/:vkey', function(req, res) {
  console.log('-------------- V -------');
  console.log(req.url);
  console.log(req.params);
  res.send('<!DOCTYPE html><html lang="en"><head><link href="/vendor/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"><script src="/vendor/bootstrap/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script></head><body><div id="vidguts"><div class="container-fluid"><div class="card mt-2"><div class="card-header"><h5>Video</h5></div><div class="card-body"><div class="row"><div class="col"><video controls="" width="100%" height="100%" autoplay=""><source src="/beach0.mp4" type="video/mp4"></video></div></div></div></div></div></div></body></html>');
});

2

From what i can see the only place where there might be an error could be the video src Try updating the path: “/beach0.mp4”, this should fix your problem, the error might be caused due to your app trying to access the video file and panicking resulting in the route being called twice.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật