【Nuxt】Does Foal support Nuxt middleware?
See original GitHub issueI try integrating Nuxt with Foal, using Foal starter like
import 'source-map-support/register'
// std
import * as http from 'http'
// 3p
import { Config, createApp } from '@foal/core'
import { connect } from 'mongoose'
// App
import { AppController } from './app/app.controller'
import express from 'express'
import Consola from 'consola'
import { Nuxt, Builder } from 'nuxt'
import config from '../nuxt.config'
const app = express()
// Import and Set Nuxt.js options
config.dev = process.env.NODE_ENV !== 'production'
async function main() {
// Init Nuxt.js
const nuxt = new Nuxt(config)
const { host, port } = nuxt.options.server
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
} else {
await nuxt.ready()
}
// Connect DB
const uri = Config.get<string>('mongodb.uri')
connect(uri, { useNewUrlParser: true, useCreateIndex: true })
let server = createApp(AppController, app)
server = http.createServer(server)
// Give nuxt middleware to express
app.use(nuxt.render)
const serverPort = Config.get('port', port)
server.listen(serverPort, host, () => {
Consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true
})
})
}
main()
But it results in 404 for the index route. It seems the controller close the stream if no method is matched. Only /api is available. Are any suggestion or demo ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Middleware directory - Nuxt
The middleware directory contains your application middleware. Middleware lets you define custom functions that can be run before rendering either a page or ......
Read more >Understanding Nuxt Middleware - Debbie O'Brien
Middleware lets you define custom functions that can be run before rendering either a page or a group of pages which we call...
Read more >Is it possible for middleware to be executed only on client side
When you execute nuxt command in spa mode, middleware will be executed only on the client side. nuxt.js/examples/spa/nuxt.config.js.
Read more >17 Nuxt JS beginner tutorial - Nuxt middleware - YouTube
Middleware runs before the page loads, so you can do authentication in nuxt using middlewaresNuxtjs Beginner Course ...
Read more >How to work with Server Middleware in Nuxt.js - YouTube
When you are know more about Middleware in Nuxt.js you will discovered you sometimes need server middleware in Nuxt.js, in this Video I...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @Fnxxxxo
Sorry for the late reply. This is not working because
createApp
takes care of returning 404 and 500 errors beforeapp.use(nuxt.render)
gets called.Correct.
Currently, there is no quick solution to make it work. Nuxt.js seems a great framework, as well as Next, and we should definitively have an easy way to integrate them with Foal.
I’ll think how to have a clean and straightforward solution to use them in the next few weeks. We should probably have something for this in August or September releases. 👍
Feature added in v1.1.0