Yang Wu
Yang Wu

Reputation: 33

express define routes confusion app.use()

app.use('/api/users',require('./routes/api/users'));

app.use('/api/auth',require('./routes/api/auth'));

app.use('/api/profile',require('./routes/api/profile'));

app.use('/api/posts',require('./routes/api/posts'))

When i change the routes from 'api' to any other words the server keep giving me 404 not found error and I also changed axio method to the corresponding words.

for example app.use('/ddd/posts',require('./routes/api/posts')) and corresponding axios: const res = await axios.get('/ddd/posts');

please help

Upvotes: 0

Views: 44

Answers (1)

jfriend00
jfriend00

Reputation: 707876

If this:

app.use('/api/posts',require('./routes/api/posts'))

works with:

axios.get('/api/posts');

Then, this:

app.use('/ddd/posts',require('./routes/api/posts'))

will work just fine with:

axios.get('/ddd/posts');

Unless there is something interfering with your modified server. Things that could be interfering:

  1. A proxy configured only to allow certain paths through
  2. Your new server didn't get started properly, perhaps because the prior generation of the server is still running

Upvotes: 1

Related Questions