Created
October 26, 2019 08:33
-
-
Save danielroe/6ebf56f5e830676496f49a692e28e9f1 to your computer and use it in GitHub Desktop.
Now / Nuxt with serverMiddleware as functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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