How to use the @nestjs/core.FastifyAdapter function in @nestjs/core

To help you get started, we’ve selected a few @nestjs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dzzzzzy / Nestjs-Learning / demo / crud-demo / src / main.ts View on Github external
async function bootstrap() {
    const app = await NestFactory.create(AppModule, new FastifyAdapter());  // 创建应用程序实例,此时所有被 AppModule 导入的其他模块的所有实例都会被加载

    // 配置文件中如果启用了 IDE,则向 fastify 注册这个 IDE 插件
    if (graphqlConfig.ide.enable) {
        app.use(graphqlConfig.ide.prefix, fastifyGraphiQL({ endpointURL: graphqlConfig.ide.endpointURL }));
    }

    // 配置 bodyParser 中间件
    app.use('/graphql', bodyParser.json());

    // 获取上下文中的 GraphQLFactory,然后解析 graphql 文件,并创建 graphql schema
    const graphQLFactory = app.get(GraphQLFactory);
    const typeDefs = graphQLFactory.mergeTypesByPaths(graphqlConfig.typeDefsPath);
    const schema = graphQLFactory.createSchema({ typeDefs });
    app.use('/graphql', fastifyGraphQL(req => ({ schema, rootValue: req })));

    await app.listen(3000);  // 使用3000端口监听应用程序
github notadd / next / src / server / server.ts View on Github external
?
            process.argv[index + 1]
            :
            serverConfiguration.http.host
                ? (
                    serverConfiguration.http.host === "*"
                        ? ip.address()
                        : serverConfiguration.http.host
                )
                :
                ip.address();
        const address = `http://${host}:${port}`;

        let application: INestApplication;
        if (serverConfiguration.adapter === "fastify") {
            const adapter = new FastifyAdapter();

            application = await NotaddFactory.startWithFastify(ApplicationModule, adapter, {
                bodyParser: true,
                cors: true,
                logger: LogService,
            });
            application.use("/", serveStatic(`${process.cwd()}/public`));
        } else {
            application = await NotaddFactory.startWithExpress(ApplicationModule, {
                bodyParser: true,
                cors: true,
                logger: LogService,
            });
            application.use(express.static(process.cwd() + "/public/"));
        }
        application.useGlobalPipes(new ValidationPipe());
github notadd / next / packages / server / server.js View on Github external
: serverConfiguration.http.port ? serverConfiguration.http.port : 3000;
        index = process.argv.indexOf("--host");
        const host = index > -1
            ?
                process.argv[index + 1]
            :
                serverConfiguration.http.host
                    ? (serverConfiguration.http.host === "*"
                        ? ip.address()
                        : serverConfiguration.http.host)
                    :
                        ip.address();
        const address = `http://${host}:${port}`;
        let application;
        if (serverConfiguration.adapter === "fastify") {
            const adapter = new core_1.FastifyAdapter();
            application = await core_2.NotaddFactory.startWithFastify(modules_1.ApplicationModule, adapter, {
                bodyParser: true,
                cors: true,
                logger: services_1.LogService,
            });
            application.use("/", serveStatic(`${process.cwd()}/public`));
        }
        else {
            application = await core_2.NotaddFactory.startWithExpress(modules_1.ApplicationModule, {
                bodyParser: true,
                cors: true,
                logger: services_1.LogService,
            });
            application.use(express.static(process.cwd() + "/public/"));
        }
        application.useGlobalPipes(new common_1.ValidationPipe());
github nestjs / terminus / sample / 001-fastify-sync / src / main.ts View on Github external
async function bootstrap() {
  const app = await NestFactory.create(ApplicationModule, new FastifyAdapter());
  await app.listen(3000);
}
bootstrap();