Skip to content

Commit 7baf303

Browse files
authored
init file-backend (#511)
1 parent 4ab870a commit 7baf303

File tree

8 files changed

+286
-1
lines changed

8 files changed

+286
-1
lines changed

apps/file-backend/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
conns/conn-*.json
3+
prisma/dev.db

apps/file-backend/jest.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
transform: {
6+
"^.+\\.ts?$": "ts-jest",
7+
},
8+
transformIgnorePatterns: ["<rootDir>/node_modules/"],
9+
};

apps/file-backend/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "api",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"scripts": {
6+
"build": "tsc",
7+
"start": "node build/run.js",
8+
"dev": "ts-node-dev src/run.ts",
9+
"test": "jest --config jest.config.js"
10+
},
11+
"dependencies": {
12+
"@apollo/client": "^3.7.1",
13+
"@codepod/prisma": "workspace:*",
14+
"@kubernetes/client-node": "^0.17.1",
15+
"@prisma/client": "4.3.1",
16+
"apollo-server": "^3.5.0",
17+
"apollo-server-core": "^3.10.3",
18+
"apollo-server-express": "3.10.2",
19+
"bcryptjs": "^2.4.3",
20+
"dockerode": "^3.3.1",
21+
"dotenv": "^16.3.1",
22+
"express": "^4.18.2",
23+
"google-auth-library": "^8.7.0",
24+
"graphql": "16.6.0",
25+
"jest": "^29.0.3",
26+
"jsdom": "^22.1.0",
27+
"jsonwebtoken": "^8.5.1",
28+
"lib0": "^0.2.83",
29+
"lodash": "^4.17.21",
30+
"nanoid": "^3.0.0",
31+
"nanoid-dictionary": "^4.3.0",
32+
"prisma": "4.3.1",
33+
"prosemirror-model": "^1.19.3",
34+
"prosemirror-view": "^1.31.7",
35+
"ws": "^8.2.3",
36+
"y-prosemirror": "^1.2.1",
37+
"y-protocols": "^1.0.5",
38+
"yjs": "^13.6.7"
39+
},
40+
"devDependencies": {
41+
"@jest/globals": "^29.6.4",
42+
"@types/bcryptjs": "^2.4.2",
43+
"@types/express": "^4.17.14",
44+
"@types/jsonwebtoken": "^8.5.9",
45+
"@types/node": "^18.11.2",
46+
"@types/ws": "^8.5.3",
47+
"ts-jest": "^29.0.1",
48+
"ts-node-dev": "^2.0.0",
49+
"typescript": "^4.4.4"
50+
}
51+
}

apps/file-backend/src/run.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { startServer } from "./server";
2+
3+
startServer({ port: 4001 });

apps/file-backend/src/server.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import express from "express";
2+
import http from "http";
3+
4+
import { ApolloServer, gql } from "apollo-server-express";
5+
6+
import { ApolloServerPluginLandingPageLocalDefault } from "apollo-server-core";
7+
8+
export const typeDefs = gql`
9+
type User {
10+
id: ID!
11+
username: String
12+
email: String!
13+
password: String!
14+
firstname: String!
15+
lastname: String!
16+
codeiumAPIKey: String
17+
}
18+
19+
type Repo {
20+
id: ID!
21+
name: String
22+
userId: ID!
23+
stargazers: [User]
24+
collaborators: [User]
25+
public: Boolean
26+
createdAt: String
27+
updatedAt: String
28+
accessedAt: String
29+
}
30+
31+
type Query {
32+
hello: String
33+
}
34+
35+
type Mutation {
36+
world: String
37+
}
38+
`;
39+
40+
export const resolvers = {
41+
Query: {
42+
hello: () => {
43+
return "Hello world!";
44+
},
45+
},
46+
Mutation: {
47+
world: () => {
48+
return "World!";
49+
},
50+
},
51+
};
52+
53+
export async function startServer({ port }) {
54+
const apollo = new ApolloServer({
55+
typeDefs,
56+
resolvers,
57+
plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })],
58+
});
59+
const expapp = express();
60+
expapp.use(express.json({ limit: "20mb" }));
61+
const http_server = http.createServer(expapp);
62+
63+
await apollo.start();
64+
apollo.applyMiddleware({ app: expapp });
65+
66+
http_server.listen({ port }, () => {
67+
console.log(`🚀 Server ready at http://localhost:${port}`);
68+
});
69+
}

apps/file-backend/tsconfig.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"outDir": "./build",
5+
"target": "esnext",
6+
"allowJs": true,
7+
"allowSyntheticDefaultImports": true,
8+
"esModuleInterop": true,
9+
"lib": ["esnext"],
10+
"moduleResolution": "node",
11+
"noFallthroughCasesInSwitch": true,
12+
"resolveJsonModule": true,
13+
"skipLibCheck": true,
14+
"strict": true,
15+
"isolatedModules": true,
16+
"noImplicitAny": false,
17+
},
18+
"ts-node": {
19+
// these options are overrides used only by ts-node
20+
// same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable
21+
"compilerOptions": {
22+
"module": "commonjs"
23+
}
24+
},
25+
"include": ["src"]
26+
}

compose/dev/compose.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,25 @@ services:
4949
volumes:
5050
- ../..:/codepod
5151
- pnpm-store:/codepod/.pnpm-store
52-
- /var/run/docker.sock:/var/run/docker.sock
5352
command: sh -c "corepack enable && pnpm dev"
5453
environment:
5554
DATABASE_URL: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?schema=public"
5655
JWT_SECRET: ${JWT_SECRET}
5756
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
5857

58+
file-backend:
59+
image: node:18
60+
working_dir: /codepod/apps/file-backend
61+
ports:
62+
- 4001:4001
63+
volumes:
64+
- ../..:/codepod
65+
- pnpm-store:/codepod/.pnpm-store
66+
command: sh -c "corepack enable && pnpm dev"
67+
environment:
68+
JWT_SECRET: ${JWT_SECRET}
69+
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
70+
5971
spawner-native:
6072
# This image has python and ipykernel installed.
6173
build:

pnpm-lock.yaml

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)