You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js中出现Cannot GET /store.html错误,求解决方法

Fixing the "Cannot GET /store.html" Error in Your Node.js/Express App

Hey there, let's break down why you're hitting that Cannot GET /store.html error and how to fix it quickly:

The Root Cause

Looking at your code, you've defined a route for /store (not /store.html) that renders the store.ejs template. When you try to access /store.html, Express doesn't have any route configured to handle that path—hence the error.

Solutions to Try

1. Access the Correct Path

The simplest fix is to visit http://your-server-url/store instead of /store.html. Your existing /store route will handle this request, read your items.json file, and render the EJS template properly.

2. Add a Route for /store.html

If you need to support the /store.html path (for compatibility or user habits), you have two options:

Option A: Redirect to /store

Add this route to your code to automatically send users to the correct path:

app.get("/store.html", (req, res) => {
  res.redirect("/store");
});
Option B: Directly Render the Template for /store.html

Duplicate (or refactor) your existing route logic to handle /store.html:

app.get("/store.html", function(req, res) {
  fs.readFile('items.json', function(error, data) {
    if (error) {
      res.status(500).end()
    } else {
      res.render('store.ejs', { stripePublicKey: stripePublicKey, items: JSON.parse(data) })
    }
  })
})

3. Double-Check Your Static Files & Template Setup

  • Make sure your store.ejs file is located in a views folder (Express looks here by default when using EJS as the view engine).
  • Confirm that items.json is in the root directory of your project (or adjust the file path in fs.readFile if it's elsewhere).
  • Since you're using app.use(express.static('public')), any files in the public folder are served as static assets—but your store page is a dynamic EJS template, so it won't be served from here unless you specifically add a static HTML file there.

内容的提问来源于stack exchange,提问作者lebaneseblonde252

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:40:34