Open patrikpessi opened 2 years ago
This is just allowing numbers with periods, specific to your use case
I wouldn't say this is specific for my project since some packages (eg. express) seem to handle such routes aswell. Working example using express:
const fs = require("fs")
const express = require("express")
const app = express()
app.use(express.static("public"))
app.get("*", (req, res) => {
const html = fs.readFileSync("public/index.html")
res.send(html.toString())
})
app.listen(3000)
Right, I’m not saying the need is specific to you (should be done) but this fix is specifically only allowing paths with dot-separated numbers, which is your use case.
I tested it on regexr and it should also allow paths with word characters aswell. Here are the tests I used. Please let me know if there is some edge case here that I'm missing?
It stops matching URLs like /foo/bar.mp3
and /foo/bar.txt.mp3
because there's a digit in the final extension segment. This is what I meant originally – the RegExp is now specifically targeting digits, which is your use case
Updated the regex for better file name/extension matching Here is another link to tests used for the regex: https://regexr.com/6fv5m
@lukeed Toughts?
132