Boilerplate Nuxt mode server with request API from Client (Proxy)
# install dependencies
$ yarn install
# serve with hot reload at localhost:3000
$ yarn dev
# build for production and launch server
$ yarn build
$ yarn start
Use request from API
After the Request, the action
'resource/method'
is executed, can be canceled by passing the parametershouldDispatch
. Example: await this.$api.[resource][method](payload, shouldDispatch)
const { data, status } = await this.$api.[resource][method](payload) // ex: this.$api.user.me({ id: 123 })
Request method in client for server default: POST
await this.$api.[resource][method](payload, 'GET', shouldDispatch) // this.$store.$api.user.me({ id: 123 }, 'GET')
Use request from Store
await this.$store.$api[resource][method](payload) // ex: this.$store.$api.user.me({ id: 123 })
Create file .env
at project root or edit /src/envs.js
SITE_URL=<url_site>
BASE_API_URL=<url_api>
PROXY_API_URL=<url_proxy>/api
For detailed explanation on how things work, check out Nuxt.js docs.