Skip to content

Instantly share code, notes, and snippets.

@wobsoriano
Created November 16, 2022 17:44
Show Gist options
  • Save wobsoriano/d9d994037a90584ced560d9b9e72422d to your computer and use it in GitHub Desktop.
Save wobsoriano/d9d994037a90584ced560d9b9e72422d to your computer and use it in GitHub Desktop.
Express in Nuxt
// ~/server/middleware/express.ts
import express from 'express'
import todoRoutes from '~/server/express/todo'
import userRoutes from '~/server/express/user'
const app = express()
app.use('/api/todos', todoRoutes)
app.use('/api/users', userRoutes)
export default fromNodeMiddleware(app)
// ~/server/express/todo.ts
import express from 'express'
const app = express.Router()
app.get('/', (req, res) => {
res.send('hello from /api/todos')
})
app.get('/:id', (req, res) => {
res.json({ id: req.params.id })
})
export default app
// ~/server/express/user.ts
import express from 'express'
const app = express.Router()
app.get('/', (req, res) => {
res.send('hello from /api/users')
})
app.get('/:id', (req, res) => {
res.json({ id: req.params.id })
})
export default app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment