ExpressJS仅在首次加载时为索引发送200状态代码。 304之后的每一次

时间:2018-02-20 22:13:37

标签: node.js express

所以我有一个运行ExpressJS的本地项目,我正在使用ejs作为我的模板引擎。每当我启动服务器并转到主页时,index.html文件都会正确呈现,但索引的每次后续加载都会为我提供未呈现的index.html文件,状态为304.所有其他页面每次都呈现正常。如果我重新启动服务器,第一次点击主页时它会正确呈现,但在此之后每次加载页面后仍然会提供未呈现的文件。如果我在路线中放置一个断点(我正在使用WebStorm),我可以在第一次达到断点,但永远不会再次。我认为这是因为304.我也有app.disable('etag')。任何帮助深表感谢。

更新 这是浏览器在收到304状态时将显示的内容。

<%- include('includes/header.html'); %>
<%- include('includes/navigation.html'); %>

<!-- Top Slider and Booking form -->
<div id="home-top-section">

    <!-- Main Slider -->
    <div id="main-slider">
        <div class="items">
            <a href="http://google.com">
                <img src="assets/img/slider/1.jpg" alt="3"/><!-- Change the URL section based on your image\'s name -->
            </a>
        </div>
        <div class="items">
            <a href="http://google.com">
                <img src="assets/img/slider/3.jpg" alt="3"/>
            </a>
        </div>
        <div class="items">
            <a href="http://google.com">
                <img src="assets/img/slider/4.jpg" alt="4"/>
            </a>
        </div>
        <div class="items">
            <a href="http://google.com">
                <img src="assets/img/slider/2.jpg" alt="2"/>
            </a>
        </div>
    </div>

    <!-- Booking Form -->
    <div class="booking-form-container container">
        <div class="booking-form-inner-container">
            <div id="main-booking-form" class="style-2">
                <h2>Find A <span>Room</span></h2>
                <form class="booking-form clearfix" action="#"><!-- Do Not remove the classes -->
                    <div class="input-daterange clearfix">
                        <div class="booking-fields col-xs-6 col-md-12">
                            <input placeholder="Choose check in date" class="datepicker-fields check-in" type="text" name="start" /><!-- Date Picker field ( Do Not remove the "datepicker-fields" class ) -->
                            <i class="fa fa-calendar"></i><!-- Date Picker Icon -->
                        </div>
                        <div class="booking-fields col-xs-6 col-md-12">
                            <input placeholder="Choose check out date" class="datepicker-fields check-out" type="text" name="end" />
                            <i class="fa fa-calendar"></i>
                        </div>
                    </div>
                    <div class="booking-fields col-xs-6 col-md-12">
                        <!-- Select boxes ( you can change the items and its value based on your project's needs ) -->
                        <select name="room-type">
                            <option value="">How Many Adult?</option><!-- Select box items ( you can change the items and its value based on your project's needs ) -->
                            <option value="2">1</option>
                            <option value="3">2</option>
                            <option value="4">3</option>
                            <option value="5">4</option>
                            <option value="6">5</option>
                        </select>
                        <!-- End of Select boxes -->
                    </div>
                    <div class="booking-fields col-xs-6 col-md-12">
                        <select name="guest">
                            <option value="">How Many Children ?</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                        </select>
                    </div>
                    <div class="booking-button-container">
                        <input class="btn btn-default" value="Check Availability" type="submit"/><!-- Submit button -->
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- End of Top Slider and Booking form -->

<!-- Luxury Rooms -->
<div id="luxury-rooms">
    <!-- Heading box -->
    <div class="heading-box">
        <h2>Luxury <span>Rooms</span></h2><!-- Title -->
        <div class="subtitle">Best rooms with Best services</div><!-- Subtitle -->
    </div>

    <!-- Room Box Container -->
    <div class="room-container container">
        <!-- Room box -->
        <div class="room-boxes">
            <img src="assets/img/rooms/1.jpg" alt="King Suit" class="room-img"><!-- Room Image -->
            <div class="room-details col-xs-6 col-md-4">
                <div class="title">King Suit</div><!-- Room title -->
                <div class="description"><!-- Room Description -->
                    Short description of rooms will be located in this section that you can describe some special features and equipment of rooms. Visitors can get more information about this rooms by clicking on "Details" button.
                </div>
                <a href="#" class="btn btn-default">Details</a><!-- Detail link -->
            </div>
            <div class="price-container col-xs-6 col-md-8">
                <div class="price">
                    <span>$550</span>
                    - Per Night
                </div>
            </div>

        </div>

        <!-- Room box -->
        <div class="room-boxes right">
            <img src="assets/img/rooms/2.jpg" alt="Royal Suit" class="room-img">
            <div class="room-details col-xs-6 col-md-4">
                <div class="title">Royal Suit</div>
                <div class="description">
                    Short description of rooms will be located in this section that you can describe some special features and equipment of rooms. Visitors can get more information about this rooms by clicking on "Details" button.
                </div>
                <a href="#" class="btn btn-default">Details</a>
            </div>
            <div class="price-container col-xs-6 col-md-8">
                <div class="price">
                    <span>$490</span>
                    - Per Night
                </div>
            </div>

        </div>
        <!-- Room box -->
        <div class="room-boxes">
            <img src="assets/img/rooms/3.jpg" alt="Deluxe Two-bedroom Suite" class="room-img">
            <div class="room-details col-xs-6 col-md-4">
                <div class="title">Deluxe Two-bedroom Suite</div>
                <div class="description">
                    Short description of rooms will be located in this section that you can describe some special features and equipment of rooms. Visitors can get more information about this rooms by clicking on "Details" button.
                </div>
                <a href="#" class="btn btn-default">Details</a>
            </div>
            <div class="price-container col-xs-6 col-md-8">
                <div class="price">
                    <span>$370</span>
                    - Per Night
                </div>
            </div>

        </div>
    </div>
</div>
<!-- End of Luxury Rooms -->

<!-- Special Packages -->
<div id="special-packages" class="container">
    <!-- Heading box -->
    <div class="heading-box">
        <h2>Special <span>Packages</span></h2><!-- Title -->
        <div class="subtitle">Choose one of our special offers</div><!-- Subtitle -->
    </div>

    <!-- Package Container -->
    <div class="package-container clearfix">
        <!-- Package Box -->
        <div class="package-box wow fadeInUp col-sm-6 col-md-4">
            <div class="package-inner">
                <div class="title">Diamond</div>
                <div class="price"><span>$450</span>per night</div>
                <div class="package-details">
                    <ul>
                        <li>Flight Ticket</li>
                        <li>Restaurant ( Lunch / Dinner )</li>
                        <li>Music Concert</li>
                        <li>Airport Pick-up</li>
                        <li>Sport Activities</li>
                    </ul>
                </div>
                <a href="#" class="btn btn-default">Select Package</a>
            </div>
        </div>

        <!-- Package Box -->
        <div class="package-box wow fadeInUp col-sm-6 col-md-4" data-wow-delay="0.5s">
            <div class="package-inner">
                <div class="title">Gold</div>
                <div class="price"><span>$340</span>per night</div>
                <div class="package-details">
                    <ul>
                        <li>Flight Ticket</li>
                        <li>Restaurant ( Lunch )</li>
                        <li>Music Concert ( 50% off )</li>
                        <li>Airport Pick-up</li>
                        <li>Sport Activities</li>                       
                    </ul>
                </div>
                <a href="#" class="btn btn-default">Select Package</a>
            </div>
        </div>

        <!-- Package Box -->
        <div class="package-box wow fadeInUp col-sm-6 col-md-4" data-wow-delay="1s">
            <div class="package-inner">
                <div class="title">Silver</div>
                <div class="price"><span>$230</span>per night</div>
                <div class="package-details">
                    <ul>
                        <li>Flight Ticket</li>
                        <li>Restaurant ( 20% off Lunch )</li>
                        <li>Music Concert ( 30% off )</li>
                        <li>Airport Pick-up</li>
                        <li>Sport Activities</li>
                    </ul>
                </div>
                <a href="#" class="btn btn-default">Select Package</a>
            </div>
        </div>

    </div>
</div>
<!-- End of Special Packages -->

<!-- Gallery -->
<div id="gallery">
    <!-- Heading box -->
    <div class="heading-box">
        <h2>Pinar <span>Gallery</span></h2><!-- Title -->
    </div>

    <!-- Gallery Container -->
    <div class="gallery-container">
        <div class="sort-section">
            <div class="sort-section-container">
                <div class="sort-handle">Filters</div>
                <ul class="list-inline">
                    <li><a href="#" data-filter="*" class="active">All</a></li>
                    <li><a href="#" data-filter=".restaurant">Restaurant</a></li>
                    <li><a href="#" data-filter=".bars">Bars</a></li>
                    <li><a href="#" data-filter=".pool">Pool</a></li>
                    <li><a href="#" data-filter=".rooms">Rooms</a></li>
                    <li><a href="#" data-filter=".lobby">Lobby</a></li>
                </ul>
            </div>
        </div>
        <ul class="image-main-box clearfix">
            <li class="item col-xs-6 col-md-3 lobby">
                <figure>
                    <img src="assets/img/gallery/1.jpg" alt="11"/>
                    <a href="assets/img/gallery/1.jpg" class="more-details" data-title="Great View">Enlarge</a>
                    <figcaption>
                        <h4><span>Great</span> View</h4>
                    </figcaption>
                </figure>
            </li>
            <li class="item col-xs-6 col-md-6 pool">
                <figure>
                    <img src="assets/img/gallery/2.jpg" alt="11"/>
                    <a href="assets/img/gallery/2.jpg" class="more-details" data-title="Outdoor Pool">Enlarge</a>
                    <figcaption>
                        <h4><span>Outdoor</span> Pool</h4>
                    </figcaption>
                </figure>
            </li>
            <li class="item col-xs-6 col-md-3 bars">
                <figure>
                    <img src="assets/img/gallery/3.jpg" alt="11"/>
                    <a href="assets/img/gallery/3.jpg" class="more-details" data-title="Delicious Foods">Enlarge</a>
                    <figcaption>
                        <h4><span>Delicious</span> Foods</h4>
                    </figcaption>
                </figure>
            </li>
            <li class="item col-xs-6 col-md-3 restaurant">
                <figure>
                    <img src="assets/img/gallery/4.jpg" alt="11"/>
                    <a href="assets/img/gallery/4.jpg" class="more-details" data-title="International Foods">Enlarge</a>
                    <figcaption>
                        <h4><span>International</span> Foods</h4>
                    </figcaption>
                </figure>
            </li>
            <li class="item col-xs-6 col-md-3 pool">
                <figure>
                    <img src="assets/img/gallery/5.jpg" alt="11"/>
                    <a href="assets/img/gallery/5.jpg" class="more-details" data-title="Cozy Spaces">Enlarge</a>
                    <figcaption>
                        <h4><span>Cozy</span> Spaces</h4>
                    </figcaption>
                </figure>
            </li>
            <li class="item col-xs-6 col-md-3 rooms">
                <figure>
                    <img src="assets/img/gallery/6.jpg" alt="11"/>
                    <a href="assets/img/gallery/6.jpg" class="more-details" data-title="Comfortable Rooms">Enlarge</a>
                    <figcaption>
                        <h4><span>Comfortable </span> Rooms</h4>
                    </figcaption>
                </figure>
            </li>
            <li class="item col-xs-6 col-md-3 pool">
                <figure>
                    <img src="assets/img/gallery/7.jpg" alt="11"/>
                    <a href="assets/img/gallery/7.jpg" class="more-details" data-title="Relaxation Spaces">Enlarge</a>
                    <figcaption>
                        <h4><span>Relaxation</span> Spaces</h4>
                    </figcaption>
                </figure>
            </li>
            <li class="item col-xs-6 col-md-6 pool">
                <figure>
                    <img src="assets/img/gallery/8.jpg" alt="11"/>
                    <a href="assets/img/gallery/8.jpg" class="more-details" data-title="Indoor Pool">Enlarge</a>
                    <figcaption>
                        <h4><span>Indoor</span> Pool</h4>
                    </figcaption>
                </figure>
            </li>
        </ul>

        <a href="#" class="btn btn-default btn-sm">More ...</a>
    </div>
</div>
<!-- End of Gallery -->

<%- include('includes/footer.html'); %>

而不是渲染版本。请注意页面顶部和底部的包含。

1 个答案:

答案 0 :(得分:2)

所以,问题只是因为我使用的是.html模板而不是.ejs。明智的话,如果您购买的模板具有静态.html文件并且想要使用模板引擎(如.ejs),请确保将.html更改为.ejs,否则您将遇到所有类型的问题。