In the project created by create-nuxt-app, accessing the koa API displays page error 404.

koa API: http://xxx,xxxxxx.com/weapp/t.

Direct address bar access display 404

it should be that nuxt accesses the weapp/token page under the page project by default. If I want to access the koa interface in the address bar, how can I?


koa-trie-router


in the APP created by nuxt-cli, if you want to access the interface API, you have to configure Koa-router

const router = require('../routes')
// [koa-router][1]
app.use(async (ctx, next) => {
    //    URL  'api/' next koa-router
    //  nuxt vue-router
    if (/api\//.test(ctx.request.url)) {
      await next()
    } else {
      ctx.status = 200
      return new Promise((resolve, reject) => {
        ctx.res.on('close', resolve)
        ctx.res.on('finish', resolve)
        nuxt.render(ctx.req, ctx.res, promise => {
          // nuxt.render passes a rejected promise into callback on error.
          promise.then(resolve).catch(reject)
        })
      })
    }
  })

  app.use(router.routes())
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b330a2-2be6e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b330a2-2be6e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?