|
|
import { NestFactory } from '@nestjs/core';
|
|
|
import { AppModule } from './app.module';
|
|
|
import { Logger } from '@nestjs/common';
|
|
|
// import { HttpExceptionFilter } from './common/HTTP-exception.filter';
|
|
|
import { options } from './config/config.doc'
|
|
|
import { SwaggerModule } from '@nestjs/swagger';
|
|
|
import { LoggingInterceptor } from './common/interceptor/logging.interceptor';
|
|
|
import * as fs from 'fs';
|
|
|
import { urlencoded, json } from 'express';
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
200 OK - [GET]:服务器成功返回用户请求的数据,该操作是幂等的(Idempotent)。
|
|
|
201 CREATED - [POST/PUT/PATCH]:用户新建或修改数据成功。
|
|
|
202 Accepted - [*]:表示一个请求已经进入后台排队(异步任务)
|
|
|
204 NO CONTENT - [DELETE]:用户删除数据成功。
|
|
|
400 INVALID REQUEST - [POST/PUT/PATCH]:用户发出的请求有错误,服务器没有进行新建或修改数据的操作,该操作是幂等的。
|
|
|
401 Unauthorized - [*]:表示用户没有权限(令牌、用户名、密码错误)。
|
|
|
403 Forbidden - [*] 表示用户得到授权(与401错误相对),但是访问是被禁止的。
|
|
|
404 NOT FOUND - [*]:用户发出的请求针对的是不存在的记录,服务器没有进行操作,该操作是幂等的。
|
|
|
406 Not Acceptable - [GET]:用户请求的格式不可得(比如用户请求JSON格式,但是只有XML格式)。
|
|
|
410 Gone -[GET]:用户请求的资源被永久删除,且不会再得到的。
|
|
|
422 Unprocesable entity - [POST/PUT/PATCH] 当创建一个对象时,发生一个验证错误。
|
|
|
500 INTERNAL SERVER ERROR - [*]:服务器发生错误,用户将无法判断发出的请求是否成功。
|
|
|
*/
|
|
|
async function bootstrap() {
|
|
|
console.log("当前运行环境 1.3.0", process.env.NODE_ENV)
|
|
|
const app = await NestFactory.create(AppModule);
|
|
|
app.enableCors({
|
|
|
origin(origin, cb) {
|
|
|
console.log('origin', origin);
|
|
|
if (process.env.NODE_ENV != "production") {
|
|
|
cb(null, true);
|
|
|
} else {
|
|
|
const CORS_ORIGIN = process.env.CORS_ORIGIN;
|
|
|
const whitelist = CORS_ORIGIN ? CORS_ORIGIN.split(',') : [];
|
|
|
cb(null, whitelist.includes(origin));
|
|
|
}
|
|
|
},
|
|
|
credentials: true,
|
|
|
});
|
|
|
app.use(json({ limit: '100mb' }));
|
|
|
app.use(urlencoded({ extended: true, limit: '100mb' }));
|
|
|
// app.useGlobalFilters(new HttpExceptionFilter());
|
|
|
app.useGlobalInterceptors(new LoggingInterceptor());
|
|
|
if (process.env.DOC === 'true') {
|
|
|
const document = SwaggerModule.createDocument(app, options);
|
|
|
if (process.env.NODE_ENV === "development" || !process.env.NODE_ENV) {
|
|
|
fs.writeFileSync("./swagger-spec.json", JSON.stringify(document));
|
|
|
}
|
|
|
SwaggerModule.setup('doc', app, document); // 设置 doc 路由
|
|
|
}
|
|
|
|
|
|
// test_e();
|
|
|
// {
|
|
|
// EidToken: '095FA750-2234-4B1C-B395-22D2197657AB',
|
|
|
// RequestId: 'ce06f1e7-163a-40ab-90c5-fc227b3ecbd2',
|
|
|
// Url: 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa50a8ac379585f53&redirect_uri=https%3A%2F%2Feid.faceid.qq.com%2Fapi%2Fv1%2FGetOpenId%3Ftoken%3D095FA750-2234-4B1C-B395-22D2197657AB%26v%3Dv2&response_type=code&scope=snsapi_base&state=&component_appid=wx9802ee81e68d6dee#wechat_redirect'
|
|
|
// }
|
|
|
|
|
|
const port: number = 9998
|
|
|
await app.listen(port);
|
|
|
Logger.log(`the server listing on ${port}`)
|
|
|
}
|
|
|
bootstrap();
|