diff --git a/packages/platform/platform-fastify/src/components/PlatformFastify.spec.ts b/packages/platform/platform-fastify/src/components/PlatformFastify.spec.ts index aa7226bef92..bf1cd2bc465 100644 --- a/packages/platform/platform-fastify/src/components/PlatformFastify.spec.ts +++ b/packages/platform/platform-fastify/src/components/PlatformFastify.spec.ts @@ -40,7 +40,7 @@ describe("PlatformFastify", () => { const stub = sandbox.stub().returns("body"); const platform = PlatformFastify.create(Server, { - koa: { + fastify: { bodyParser: stub } }); @@ -54,7 +54,7 @@ describe("PlatformFastify", () => { const stub = sandbox.stub().returns("body"); const platform = PlatformFastify.create(Server, { - koa: { + fastify: { bodyParser: stub } }); @@ -68,7 +68,7 @@ describe("PlatformFastify", () => { const stub = sandbox.stub().returns("body"); const platform = PlatformFastify.create(Server, { - koa: { + fastify: { bodyParser: stub } }); diff --git a/packages/platform/platform-fastify/src/components/PlatformFastify.ts b/packages/platform/platform-fastify/src/components/PlatformFastify.ts index 3b607e76365..bf5684d143e 100644 --- a/packages/platform/platform-fastify/src/components/PlatformFastify.ts +++ b/packages/platform/platform-fastify/src/components/PlatformFastify.ts @@ -16,7 +16,6 @@ import {Type} from "@tsed/core"; import {PlatformHandlerMetadata, PlatformLayer} from "@tsed/platform-router"; import next from "ajv/dist/vocabularies/next"; import Fastify, {FastifyInstance, FastifyReply, FastifyRequest} from "fastify"; -import Koa from "koa"; import {PlatformFastifyApplication} from "../services/PlatformFastifyApplication"; import {PlatformFastifyHandler} from "../services/PlatformFastifyHandler"; import {PlatformFastifyRequest} from "../services/PlatformFastifyRequest"; @@ -32,7 +31,7 @@ declare global { /** * @platform - * @koa + * @fastify */ export class PlatformFastify implements PlatformAdapter { readonly providers = [ diff --git a/packages/platform/platform-fastify/src/interfaces/interfaces.ts b/packages/platform/platform-fastify/src/interfaces/interfaces.ts index 2a1697b7314..07e81585f0a 100644 --- a/packages/platform/platform-fastify/src/interfaces/interfaces.ts +++ b/packages/platform/platform-fastify/src/interfaces/interfaces.ts @@ -1,5 +1,4 @@ -import Koa from "koa"; -import {PlatformKoaSettings} from "./PlatformFastifySettings"; +import {PlatformFastifySettings} from "./PlatformFastifySettings"; export * from "./PlatformFastifySettings"; @@ -9,9 +8,9 @@ declare global { /** * Configuration related to Koa platform application. */ - koa: PlatformKoaSettings; + fastify: PlatformFastifySettings; } - export interface NextFunction extends Koa.Next {} + // export interface NextFunction extends Fastify.Next {} } } diff --git a/packages/platform/platform-fastify/src/services/PlatformFastifyRequest.spec.ts b/packages/platform/platform-fastify/src/services/PlatformFastifyRequest.spec.ts index 40cc4068859..b9cfba02d9a 100644 --- a/packages/platform/platform-fastify/src/services/PlatformFastifyRequest.spec.ts +++ b/packages/platform/platform-fastify/src/services/PlatformFastifyRequest.spec.ts @@ -1,37 +1,37 @@ import {PlatformTest} from "@tsed/common"; -import {PlatformKoaRequest} from "@tsed/platform-koa"; +import {PlatformFastifyRequest} from "../.."; import {expect} from "chai"; function createRequest() { const request = PlatformTest.createRequest(); - const koaCtx = { - request: { - protocol: "http", - req: request - }, - cookie: { - test: "test" - }, - cookies: { - test: "test" - }, - session: { - test: "test" - } - }; - request.ctx = koaCtx; + // const fastifyCtx = { + // request: { + // protocol: "http", + // req: request + // }, + // cookie: { + // test: "test" + // }, + // cookies: { + // test: "test" + // }, + // session: { + // test: "test" + // } + // }; + // request.ctx = koaCtx; const ctx = PlatformTest.createRequestContext({ event: { - request, - ctx: koaCtx + request + // ctx: koaCtx }, - RequestKlass: PlatformKoaRequest + RequestKlass: PlatformFastifyRequest }); return {req: request, request: ctx.request}; } -describe("PlatformKoaRequest", () => { +describe("PlatformFastifyRequest", () => { beforeEach(() => PlatformTest.create()); afterEach(() => PlatformTest.reset()); it("should create a PlatformRequest instance", () => { diff --git a/packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts b/packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts index 3a5aeed34fb..ff2c86224d2 100644 --- a/packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts +++ b/packages/platform/platform-fastify/src/services/PlatformFastifyRequest.ts @@ -1,5 +1,5 @@ -import {IncomingEvent, PlatformContext, PlatformRequest} from "@tsed/common"; -import Koa, {FastifyRequest} from "fastify"; +import {PlatformContext, PlatformRequest} from "@tsed/common"; +import {FastifyRequest} from "fastify"; import {IncomingMessage} from "http"; declare module "fastify" { diff --git a/packages/platform/platform-fastify/src/services/PlatformFastifyResponse.spec.ts b/packages/platform/platform-fastify/src/services/PlatformFastifyResponse.spec.ts index 5f3e71b3a35..caf2a7b56c9 100644 --- a/packages/platform/platform-fastify/src/services/PlatformFastifyResponse.spec.ts +++ b/packages/platform/platform-fastify/src/services/PlatformFastifyResponse.spec.ts @@ -1,32 +1,24 @@ import {PlatformTest} from "@tsed/common"; -import {PlatformKoaResponse} from "@tsed/platform-koa"; import {expect} from "chai"; import Sinon from "sinon"; +import {PlatformFastifyResponse} from "./PlatformFastifyResponse"; const sandbox = Sinon.createSandbox(); function createResponse() { const response = PlatformTest.createResponse(); - const koaCtx = { - response: { - res: response - } - }; - - response.ctx = koaCtx; const ctx = PlatformTest.createRequestContext({ event: { - response, - ctx: koaCtx + response }, - ResponseKlass: PlatformKoaResponse + ResponseKlass: PlatformFastifyResponse }); return {res: response, response: ctx.response}; } -describe("PlatformKoaResponse", () => { +describe("PlatformFastifyResponse", () => { beforeEach(() => PlatformTest.create()); afterEach(() => PlatformTest.reset()); it("should create a PlatformResponse instance", () => { @@ -46,7 +38,7 @@ describe("PlatformKoaResponse", () => { }); }); describe("statusCode", () => { - it("return statusCode", async () => { + it("return statusCode", () => { const {response} = createResponse(); response.status(302); @@ -55,7 +47,7 @@ describe("PlatformKoaResponse", () => { }); }); describe("hasStatus", () => { - it("return hasStatus", async () => { + it("return hasStatus", () => { const {response} = createResponse(); response.status(404); @@ -67,7 +59,7 @@ describe("PlatformKoaResponse", () => { }); }); describe("contentType()", () => { - it("should set contentType", async () => { + it("should set contentType", () => { const {res, response} = createResponse(); response.contentType("text/html"); @@ -76,7 +68,7 @@ describe("PlatformKoaResponse", () => { }); }); describe("body()", () => { - it("should set body", async () => { + it("should set body", () => { const {res, response} = createResponse(); response.body("body"); diff --git a/packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts b/packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts index f4a290f63d4..a8d64bce3f9 100644 --- a/packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts +++ b/packages/platform/platform-fastify/src/services/PlatformFastifyResponse.ts @@ -12,7 +12,7 @@ declare global { /** * @platform - * @koa + * @fastify */ export class PlatformFastifyResponse extends PlatformResponse { get statusCode() { @@ -30,10 +30,9 @@ export class PlatformFastifyResponse extends PlatformResponse { return this.raw.raw; } - hasStatus() { - // KOA set 404 by default - return this.statusCode !== 404; - } + // hasStatus() { + // return this.statusCode !== 404; + // } /** * Sets the HTTP status for the response. diff --git a/packages/platform/platform-fastify/test/app/Server.ts b/packages/platform/platform-fastify/test/app/Server.ts index 36eacef2736..e544fa9d587 100644 --- a/packages/platform/platform-fastify/test/app/Server.ts +++ b/packages/platform/platform-fastify/test/app/Server.ts @@ -1,12 +1,6 @@ import "@tsed/ajv"; import {PlatformApplication} from "@tsed/common"; import {Configuration, Inject} from "@tsed/di"; -import Application from "koa"; -import bodyParser from "koa-bodyparser"; -import compress from "koa-compress"; -import session from "koa-session"; -// @ts-ignore -import methodOverride from "koa-override"; export const rootDir = __dirname; @@ -25,37 +19,4 @@ export const rootDir = __dirname; export class Server { @Inject() app: PlatformApplication; - - $beforeRoutesInit() { - this.app.getApp().keys = ["some secret hurr"]; - this.app - .use(compress()) - .use(methodOverride()) - .use( - session( - { - key: "connect.sid" /** (string) cookie key (default is koa.sess) */, - /** (number || 'session') maxAge in ms (default is 1 days) */ - /** 'session' will result in a cookie that expires when session/browser is closed */ - /** Warning: If a session cookie is stolen, this cookie will never expire */ - maxAge: 86400000, - /** (boolean) automatically commit headers (default true) */ - overwrite: true, - /** (boolean) can overwrite or not (default true) */ - httpOnly: false, - /** (boolean) httpOnly or not (default true) */ - signed: false, - /** (boolean) signed or not (default true) */ - rolling: false, - /** (boolean) Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. (default is false) */ - renew: false, - /** (boolean) renew session when session is nearly expired, so we can always keep user logged in. (default is false)*/ - secure: false, - /** (boolean) secure cookie*/ - sameSite: undefined /** (string) session cookie sameSite options (default null, don't set it) */ - }, - this.app.rawApp as any - ) - ); - } }