Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

servermiddleware -- config vars #341

@34r7h

Description

@34r7h

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)); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions