Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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端口监听应用程序
?
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());
: 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());
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule, new FastifyAdapter());
await app.listen(3000);
}
bootstrap();