Created
November 16, 2022 17:44
-
-
Save wobsoriano/d9d994037a90584ced560d9b9e72422d to your computer and use it in GitHub Desktop.
Express in Nuxt
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
// ~/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) |
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
// ~/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 |
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
// ~/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