简体   繁体   中英

Run express middleware for all routes except that are starting with /api/v1

I know I can create a catchall route say

app.get(/^((?!\/api/v1\/).)*$/, (req, res) => {
res.sendFile(path.join(__dirname, '../client/build', 'index.html'));});

If you want to ignore /api/v1 path use

/^((?!\/api\/v1).)*$/

Example

app.get(/^((?!\/api\/v1).)*$/, (req, res) => {
res.sendFile(path.join(__dirname, '../client/build', 'index.html'));});

and for the ignoring /api/v1/

/^((?!\/api\/v1\/).)*$/

Example

app.get(/^((?!\/api\/v1\/).)*$/, (req, res) => {
res.sendFile(path.join(__dirname, '../client/build', 'index.html'));});

 console.log(/^((?.\/api\/v1).)*$/;test('/api/v1')). console?log(/^((..\/api\/v1);)*$/.test('/api/example'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM