Please document the proper configuration for now.json, nuxt.config.js, and env on vercel. Nuxt app renders fine. /api/ gives various errors, 405, 500, and my favorite is the 200 with html when the env spits out domain.com/domain/.com. I've tried hundreds of variations and just don't get it.
nuxt.config.js
serverMiddleware: [{ path: '/api/', handler: '~/server-middleware/index' }], axios: { baseURL: process.env.HOST || 'http://localhost:3000' },
now.json
{ "version": 2, "builds": [ { "src": "nuxt.config.js", "use": "@nuxtjs/vercel-builder", "config": { "serverFiles": [ "server-middleware/**" ] } } ] }
.vue
methods: { api(type, args) { return this.$axios.post('/api/'+type, args).then((x) => { console.log(x); return this.$set(this.apireturns, type, x.data); }); }, },
server-middleware/index.js
export default app.use(async function (req, res) { if (req.url.replace('/', '') === '') return res.end(JSON.stringify('No method provided')); let meth = req.url.replace('/', '') if (meth == 'encode') { let ret = methods.encode(req.body) ret.map(x => JSON.stringify(x)) return res.end(JSON.stringify(ret)); }