-
-
Notifications
You must be signed in to change notification settings - Fork 22.1k
Labels
Description
Error while server client as static in express 5.0.1 and 5.1.0. for 4.21.2 working fine
shivams@shivam MINGW64 ~/Desktop/my-projects/blog-app/server (main)
$ node --run start
C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:73
throw new TypeError(`Missing parameter name at ${i}: ${DEBUG_URL}`);
^
TypeError: Missing parameter name at 1: https://git.new/pathToRegexpError
at name (C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:73:19)
at lexer (C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:91:27)
at lexer.next (<anonymous>)
at Iter.peek (C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:106:38)
at Iter.tryConsume (C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:112:28)
at Iter.text (C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:128:30)
at consume (C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:152:29)
at parse (C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:183:20)
at C:\Users\shivams\Desktop\my-projects\blog-app\server\node_modules\path-to-regexp\dist\index.js:294:74
at Array.map (<anonymous>)
Node.js v22.13.1
Failed running 'server.js'Environment information
Version:
Platform:
Window 11
Node.js version:
22.13.1
Any other relevant information:
What steps will reproduce the bug?
import express from "express";
import cors from "cors"
import path from "node:path"
import connectDB from "./db/db.js";
import userRoutes from "./routes/user.route.js";
import postRoutes from "./routes/post.route.js";
import commentRoutes from "./routes/comment.route.js"
import clerkRoutes from "./routes/webhook.route.js"
import { clerkMiddleware } from '@clerk/express'
const app = express();
const PORT = process.env.PORT;
app.use(cors({
origin: process.env.ORIGIN
}));
app.use(clerkMiddleware())
app.use("/webhooks", clerkRoutes);
app.use(express.json());
// allow cross-origin requests
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use("/api/users", userRoutes)
app.use("/api/posts", postRoutes);
app.use("/api/comments", commentRoutes);
const __dirname = path.resolve();
app.use(express.static(path.join(__dirname,'/client/dist')));
app.get('*',(req,res)=>{
res.sendFile(path.join(__dirname,"client","dist","index.html"));
})
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
message: error.message || "Something went wrong",
status: error.status,
stack: error.stack,
});
});
app.listen(PORT, async (error) => {
if (error) {
throw error;
}
await connectDB();
console.log(`Application running on ${PORT}`);
});