diff --git a/server/.dockerignore b/server/.dockerignore new file mode 100644 index 00000000..5171c540 --- /dev/null +++ b/server/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 00000000..a4cd4dfc --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,22 @@ +FROM node:14 + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +# A wildcard is used to ensure both package.json AND package-lock.json are copied +# where available (npm@5+) +COPY package.json ./ +COPY yarn.lock ./ + +RUN yarn + +COPY . . + +RUN yarn build + +ENV NODE_ENV production + +EXPOSE 8080 +CMD [ "node", "dist/index.js" ] +USER node \ No newline at end of file diff --git a/server/package.json b/server/package.json index dcccc976..648e954e 100644 --- a/server/package.json +++ b/server/package.json @@ -4,6 +4,7 @@ "description": "", "main": "index.js", "scripts": { + "build": "tsc", "watch": "tsc -w", "dev": "nodemon dist/index.js", "start": "node dist/index.js", diff --git a/server/src/entities/Updoot.ts b/server/src/entities/Updoot.ts index dd23efe8..895e24e3 100644 --- a/server/src/entities/Updoot.ts +++ b/server/src/entities/Updoot.ts @@ -1,4 +1,3 @@ -import { ObjectType, Field } from "type-graphql"; import { Entity, BaseEntity, ManyToOne, PrimaryColumn, Column } from "typeorm"; import { User } from "./User"; import { Post } from "./Post"; diff --git a/server/src/resolvers/post.ts b/server/src/resolvers/post.ts index 8266cef5..fbd7994e 100644 --- a/server/src/resolvers/post.ts +++ b/server/src/resolvers/post.ts @@ -1,25 +1,23 @@ import { - Resolver, - Query, Arg, - Mutation, - InputType, - Field, Ctx, - UseMiddleware, - Int, + Field, FieldResolver, - Root, + InputType, + Int, + Mutation, ObjectType, - Info, + Query, + Resolver, + Root, + UseMiddleware, } from "type-graphql"; -import { Post } from "../entities/Post"; -import { MyContext } from "../types"; -import { isAuth } from "../middleware/isAuth"; import { getConnection } from "typeorm"; +import { Post } from "../entities/Post"; import { Updoot } from "../entities/Updoot"; -import { tmpdir } from "os"; import { User } from "../entities/User"; +import { isAuth } from "../middleware/isAuth"; +import { MyContext } from "../types"; @InputType() class PostInput { @@ -128,8 +126,7 @@ export class PostResolver { @Query(() => PaginatedPosts) async posts( @Arg("limit", () => Int) limit: number, - @Arg("cursor", () => String, { nullable: true }) cursor: string | null, - @Ctx() { req }: MyContext + @Arg("cursor", () => String, { nullable: true }) cursor: string | null ): Promise { // 20 -> 21 const realLimit = Math.min(50, limit); diff --git a/server/src/utils/createUpdootLoader.ts b/server/src/utils/createUpdootLoader.ts index f720fc6d..00836551 100644 --- a/server/src/utils/createUpdootLoader.ts +++ b/server/src/utils/createUpdootLoader.ts @@ -1,4 +1,3 @@ -import { User } from "../entities/User"; import { Updoot } from "../entities/Updoot"; import DataLoader from "dataloader";