这个主意
首先,您拥有一个与其他网站一样的主要Nuxt网站。然后,将我的模块添加到您的项目中。然后,我的模块将一个子域“ admin.example.com”添加到您的项目中,该子域是一个完全充实的基于Nuxt的网站,但完全在您的项目流程中运行,因此不必制作两个必须分别启动的网站项目,我的想法是,我可以先创建一个网站项目,然后创建一个模块项目,再添加另一个网站,然后将三个项目变成两个。
码
module.js
this.addServerMiddleware(vhost('admin.website.com', adminApp));
adminApp.js
const {Nuxt, Builder} = require('nuxt');
const config = require('../admin/nuxt.config');
config.dev = true;
const nuxt = new Nuxt(config);
if (nuxt.options.dev) {
new Builder(nuxt).build()
.catch(function(error) {
console.log(error);
})
}
module.exports = nuxt.render;
管理网站中nuxt.config.js的一部分
// __dirname leads to my modules directory
// process.cwd() leads to the main websites folder
module.exports = {
mode: 'universal',
srcDir: __dirname,
rootDir: __dirname,
modulesDir: process.cwd(),
问题
每当我转到“ admin.website.com”时,都会显示以下消息:
I've tried tonnes various changes and tweaks already but nothing seems to be working. As far as I can tell it might have to do with the fact that either A) the website gets built somewhere it doesn't find the generated resource files, or B) that I haven't prayed enough to the spaghetti monster.
I've tried exporting adminApp
as an Express app that uses app.use(nuxt.render)
but that results in the same error so I'm certain that's not the issue. I've tried using an Express app for api.website.com
and that works just fine, so I know I'm like THIS |--| close to making this all work. Adding subdomains like this does work and each subdomain can be an Express app, but for some reason Nuxt can't find any resources when used this way. According to https://nuxtjs.org/api/nuxt-render/ nuxt.render(req, res)
as you can see takes req
and res
as arguments, which should mean I don't need to use it via an Express app, serverMiddleware
is already an Express app.
Thoughts?
通过无服务器提供应用程序之前,我遇到了此错误。我认为您需要在nuxt.config.js中为这两个应用程序显式设置publicPath或buildDir,以使安装工作正常。您的问题可能是所有构建资产都在同一文件夹中生成,导致其中一个应用程序找不到构建资产。在nuxt.config.js上设置buildDir属性,并在build属性上定义publicPath设置。
更多信息在这里:
https://nuxtjs.org/api/configuration-builddir
https://nuxtjs.org/api/configuration-build#publicpath