Skip to content

Instantly share code, notes, and snippets.

@danielroe
Created October 26, 2019 08:33
Show Gist options
  • Save danielroe/6ebf56f5e830676496f49a692e28e9f1 to your computer and use it in GitHub Desktop.
Save danielroe/6ebf56f5e830676496f49a692e28e9f1 to your computer and use it in GitHub Desktop.
Now / Nuxt with serverMiddleware as functions
import express from 'express'
const app = express()
app.use(express.json())
app.post('/endpoint', function(req, res) {
try {
// Do stuff
res.status(200).end()
} catch (e) {
res.status(422).end()
}
})
export default app
{
"name": "example",
"version": 2,
"builds": [
{
"src": "api/endpoint.js",
"use": "@now/node"
},
{
"src": "frontend/nuxt.config.js",
"use": "@nuxtjs/now-builder"
}
],
"routes": [
{
"src": "/endpoint",
"dest": "/api/endpoint.js",
"methods": ["POST", "OPTIONS"],
"headers": {
"cache-control": "s-maxage=31536000, max-age=0",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type"
}
}
]
}
...
serverMiddleware: process.env.NODE_ENV === 'production' ? [] : ['~/api/endpoint.js'],
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment