NestJS + NuxtJS(在 TypeScript 中)
NestJS + NuxtJS (in TypeScript)
我目前正在寻找已经在 TypeScript 中使用带有 SSR(服务器端渲染)的 NestJS(背面)和 NuxtJS(前端)准备入门套件的人。
我想学习这两个技术,但我没有找到足够的帮助来从头开始构建项目。
我对 Nuxt 感兴趣的是创建页面的简便性,而对于 Nest,它也非常完整且易于创建 APIs。
我在 Github 上找到了一些存储库,里面有很多旧东西,包更新让一切都变得跳跃起来。
我创建了合适的项目:https://github.com/pirmax/nuxt-and-nest
但是,如果我删除 NuxtJS 集成,https://localhost:3000/api 上的 API 路由 运行 或 Nuxt 路由都可以工作。
async function bootstrap() {
const nuxt = await new Nuxt(config);
config.dev = !(process.env.NODE_ENV === "production");
if (config.dev) {
await new Builder(nuxt).build();
}
const app = await NestFactory.create(AppModule);
await app.setGlobalPrefix("api");
await app.listen(3000, () => console.log("Application is listening on port 3000."));
await app.use(nuxt.render);
}
bootstrap();
现在,我有这个错误:
bundle export should be a function when using { runInNewContext: false
}.
如果刷新页面:
runner is not a function
也许这会有所帮助:
import { NestFactory } from '@nestjs/core';
import { ServerModule } from './server.module';
const { Nuxt, Builder } = require('nuxt');
const config = require('../nuxt.config.js');
config.dev = process.env.NODE_ENV !== 'production';
async function bootstrap() {
const app = await NestFactory.create(ServerModule);
const nuxt = new Nuxt(config);
const { host, port } = nuxt.options.server;
if (config.dev) {
const builder = new Builder(nuxt);
await builder.build();
} else {await nuxt.ready();}
app.use(nuxt.render);
await app.listen(port, host);
}
bootstrap();
如果您使用 nest 作为连接中间件,您可以通过 servermiddleware
nuxt 配置选项将 nest 与 nuxt 结合使用。也许这个要点可以给你一个大概的想法:
https://gist.github.com/1isten/ed286c3980523f4a4f9b6b627f540091
我目前正在寻找已经在 TypeScript 中使用带有 SSR(服务器端渲染)的 NestJS(背面)和 NuxtJS(前端)准备入门套件的人。
我想学习这两个技术,但我没有找到足够的帮助来从头开始构建项目。
我对 Nuxt 感兴趣的是创建页面的简便性,而对于 Nest,它也非常完整且易于创建 APIs。
我在 Github 上找到了一些存储库,里面有很多旧东西,包更新让一切都变得跳跃起来。
我创建了合适的项目:https://github.com/pirmax/nuxt-and-nest 但是,如果我删除 NuxtJS 集成,https://localhost:3000/api 上的 API 路由 运行 或 Nuxt 路由都可以工作。
async function bootstrap() {
const nuxt = await new Nuxt(config);
config.dev = !(process.env.NODE_ENV === "production");
if (config.dev) {
await new Builder(nuxt).build();
}
const app = await NestFactory.create(AppModule);
await app.setGlobalPrefix("api");
await app.listen(3000, () => console.log("Application is listening on port 3000."));
await app.use(nuxt.render);
}
bootstrap();
现在,我有这个错误:
bundle export should be a function when using { runInNewContext: false }.
如果刷新页面:
runner is not a function
也许这会有所帮助:
import { NestFactory } from '@nestjs/core';
import { ServerModule } from './server.module';
const { Nuxt, Builder } = require('nuxt');
const config = require('../nuxt.config.js');
config.dev = process.env.NODE_ENV !== 'production';
async function bootstrap() {
const app = await NestFactory.create(ServerModule);
const nuxt = new Nuxt(config);
const { host, port } = nuxt.options.server;
if (config.dev) {
const builder = new Builder(nuxt);
await builder.build();
} else {await nuxt.ready();}
app.use(nuxt.render);
await app.listen(port, host);
}
bootstrap();
如果您使用 nest 作为连接中间件,您可以通过 servermiddleware
nuxt 配置选项将 nest 与 nuxt 结合使用。也许这个要点可以给你一个大概的想法:
https://gist.github.com/1isten/ed286c3980523f4a4f9b6b627f540091