Skip to content

Commit 436a79d

Browse files
committed
Initial commit
0 parents  commit 436a79d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+870
-0
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
extends: [
3+
"eslint:strict",
4+
"plugin:@typescript-eslint/strict-type-checked",
5+
"plugin:@typescript-eslint/stylistic",
6+
],
7+
};

.gitignore

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
15+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
16+
17+
# Runtime data
18+
19+
pids
20+
_.pid
21+
_.seed
22+
\*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
26+
lib-cov
27+
28+
# Coverage directory used by tools like istanbul
29+
30+
coverage
31+
\*.lcov
32+
33+
# nyc test coverage
34+
35+
.nyc_output
36+
37+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
38+
39+
.grunt
40+
41+
# Bower dependency directory (https://bower.io/)
42+
43+
bower_components
44+
45+
# node-waf configuration
46+
47+
.lock-wscript
48+
49+
# Compiled binary addons (https://nodejs.org/api/addons.html)
50+
51+
build/Release
52+
53+
# Dependency directories
54+
55+
node_modules/
56+
jspm_packages/
57+
58+
# Snowpack dependency directory (https://snowpack.dev/)
59+
60+
web_modules/
61+
62+
# TypeScript cache
63+
64+
\*.tsbuildinfo
65+
66+
# Optional npm cache directory
67+
68+
.npm
69+
70+
# Optional eslint cache
71+
72+
.eslintcache
73+
74+
# Optional stylelint cache
75+
76+
.stylelintcache
77+
78+
# Microbundle cache
79+
80+
.rpt2_cache/
81+
.rts2_cache_cjs/
82+
.rts2_cache_es/
83+
.rts2_cache_umd/
84+
85+
# Optional REPL history
86+
87+
.node_repl_history
88+
89+
# Output of 'npm pack'
90+
91+
\*.tgz
92+
93+
# Yarn Integrity file
94+
95+
.yarn-integrity
96+
97+
# dotenv environment variable files
98+
99+
.env
100+
.env.development.local
101+
.env.test.local
102+
.env.production.local
103+
.env.local
104+
105+
# parcel-bundler cache (https://parceljs.org/)
106+
107+
.cache
108+
.parcel-cache
109+
110+
# Next.js build output
111+
112+
.next
113+
out
114+
115+
# Nuxt.js build / generate output
116+
117+
.nuxt
118+
dist
119+
120+
# Gatsby files
121+
122+
.cache/
123+
124+
# Comment in the public line in if your project uses Gatsby and not Next.js
125+
126+
# https://nextjs.org/blog/next-9-1#public-directory-support
127+
128+
# public
129+
130+
# vuepress build output
131+
132+
.vuepress/dist
133+
134+
# vuepress v2.x temp and cache directory
135+
136+
.temp
137+
.cache
138+
139+
# Docusaurus cache and generated files
140+
141+
.docusaurus
142+
143+
# Serverless directories
144+
145+
.serverless/
146+
147+
# FuseBox cache
148+
149+
.fusebox/
150+
151+
# DynamoDB Local files
152+
153+
.dynamodb/
154+
155+
# TernJS port file
156+
157+
.tern-port
158+
159+
# Stores VSCode versions used for testing VSCode extensions
160+
161+
.vscode-test
162+
163+
# yarn v2
164+
165+
.yarn/cache
166+
.yarn/unplugged
167+
.yarn/build-state.yml
168+
.yarn/install-state.gz
169+
.pnp.\*
170+
config/config.toml

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# fedi-project
2+
3+
To install dependencies:
4+
5+
```bash
6+
bun install
7+
```
8+
9+
To run:
10+
11+
```bash
12+
bun run index.ts
13+
```
14+
15+
This project was created using `bun init` in bun v0.8.1. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

bun.lockb

69.6 KB
Binary file not shown.

database/datasource.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { DataSource } from "typeorm";
2+
import { getConfig } from "../utils/config";
3+
4+
const config = getConfig();
5+
6+
const AppDataSource = new DataSource({
7+
type: "postgres",
8+
host: config.database.host,
9+
port: config.database.port,
10+
username: config.database.username,
11+
password: config.database.password,
12+
database: config.database.database,
13+
synchronize: true,
14+
entities: ["./entities/*.ts"],
15+
});
16+
17+
export { AppDataSource };

database/entities/User.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
2+
3+
@Entity({
4+
name: "users",
5+
})
6+
export class User extends BaseEntity {
7+
@PrimaryGeneratedColumn("uuid")
8+
id!: string;
9+
10+
@Column("varchar")
11+
username!: string;
12+
13+
@Column("varchar")
14+
password!: string;
15+
16+
@CreateDateColumn()
17+
created_at!: Date;
18+
19+
@UpdateDateColumn()
20+
updated_at!: Date;
21+
}

index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const router = new Bun.FileSystemRouter({
2+
style: "nextjs",
3+
dir: process.cwd() + "/server/api",
4+
})
5+
6+
Bun.serve({
7+
port: 8080,
8+
hostname: "0.0.0.0", // defaults to "0.0.0.0"
9+
async fetch(req) {
10+
const url = new URL(req.url);
11+
12+
const matchedRoute = router.match(req);
13+
14+
if (matchedRoute) {
15+
return (await import(matchedRoute.filePath)).default(req, matchedRoute);
16+
} else {
17+
const response = new Response(undefined, {
18+
status: 404,
19+
statusText: "Route not found",
20+
});
21+
}
22+
},
23+
});

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "fedi-project",
3+
"module": "index.ts",
4+
"type": "module",
5+
"devDependencies": {
6+
"@typescript-eslint/eslint-plugin": "^6.6.0",
7+
"bun-types": "latest",
8+
"eslint": "^8.49.0"
9+
},
10+
"peerDependencies": {
11+
"typescript": "^5.0.0"
12+
},
13+
"dependencies": {
14+
"pg": "^8.11.3",
15+
"typeorm": "^0.3.17"
16+
}
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { jsonResponse } from "@response";
2+
import { MatchedRoute } from "bun";
3+
import { User } from "~database/entities/User";
4+
5+
export default async (
6+
req: Request,
7+
matchedRoute: MatchedRoute
8+
): Promise<Response> => {
9+
const id = matchedRoute.params.id;
10+
11+
const user = await User.findOneBy({
12+
id,
13+
});
14+
15+
if (!user)
16+
return jsonResponse(
17+
{
18+
statusText: "User not found",
19+
},
20+
404
21+
);
22+
23+
return jsonResponse({
24+
id,
25+
});
26+
};

tsconfig.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["ESNext"],
4+
"module": "esnext",
5+
"target": "esnext",
6+
"moduleResolution": "bundler",
7+
"moduleDetection": "force",
8+
"allowImportingTsExtensions": true,
9+
"noEmit": true,
10+
"composite": true,
11+
"strict": true,
12+
"downlevelIteration": true,
13+
"skipLibCheck": true,
14+
"noImplicitAny": true,
15+
"jsx": "preserve",
16+
"allowSyntheticDefaultImports": true,
17+
"strictNullChecks": true,
18+
"strictFunctionTypes": true,
19+
"forceConsistentCasingInFileNames": true,
20+
"allowJs": true,
21+
"experimentalDecorators": true,
22+
"types": [
23+
"bun-types" // add Bun global
24+
],
25+
"paths": {
26+
"@*": ["./utils/*"],
27+
"~*": ["./*"]
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)