Initial code
This commit is contained in:
parent
f4a1afe71b
commit
c6d3e066c9
21 changed files with 2446 additions and 0 deletions
4
src/config.json
Normal file
4
src/config.json
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"port": 3012,
|
||||
"db": "db.json"
|
||||
}
|
||||
3
src/config.ts
Normal file
3
src/config.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import config from "./config.json" with { type: "json" };
|
||||
|
||||
export { config };
|
||||
2
src/controllers/test/index.ts
Normal file
2
src/controllers/test/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./test.js";
|
||||
export * from "./routes.js";
|
||||
8
src/controllers/test/routes.ts
Normal file
8
src/controllers/test/routes.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { type FastifyInstance } from "fastify";
|
||||
import * as controller from "./test.js";
|
||||
|
||||
const testRoutes = async (fastify: FastifyInstance) => {
|
||||
fastify.get("/test", controller.test);
|
||||
};
|
||||
|
||||
export { testRoutes };
|
||||
10
src/controllers/test/test.ts
Normal file
10
src/controllers/test/test.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { type FastifyReply, type FastifyRequest } from "fastify";
|
||||
import { testdb } from "../../store/store.js";
|
||||
|
||||
const test = async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
testdb();
|
||||
|
||||
return [{ name: "Alice" }];
|
||||
};
|
||||
|
||||
export { test };
|
||||
15
src/index.ts
Normal file
15
src/index.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { config } from "./config.js";
|
||||
|
||||
import Fastify from "fastify";
|
||||
import { testRoutes } from "./controllers/test/routes.js";
|
||||
|
||||
const app = Fastify({
|
||||
logger: true,
|
||||
});
|
||||
|
||||
app.register(testRoutes);
|
||||
|
||||
app.listen({ port: config.port }, (err, address) => {
|
||||
if (err) throw err;
|
||||
console.log(`Server is now listening on ${address}`);
|
||||
});
|
||||
2
src/store/index.ts
Normal file
2
src/store/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./store.js";
|
||||
export * from "./types.js";
|
||||
27
src/store/store.ts
Normal file
27
src/store/store.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { PrismaClient } from "../generated/prisma/client.js";
|
||||
|
||||
import { PrismaPg } from "@prisma/adapter-pg";
|
||||
import { Pool } from "pg";
|
||||
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
|
||||
const pool = new Pool({ connectionString });
|
||||
const adapter = new PrismaPg(pool);
|
||||
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
|
||||
async function testdb() {
|
||||
const test = await prisma.user.findMany();
|
||||
/*
|
||||
const user = await prisma.user.create({
|
||||
data: { name: "Alice", email: `alice${Math.random()}@example.com` },
|
||||
});
|
||||
|
||||
console.log("Created user:", user);
|
||||
|
||||
const test = await prisma.user.findMany();
|
||||
console.log(test);
|
||||
*/
|
||||
}
|
||||
|
||||
export { testdb };
|
||||
3
src/store/types.ts
Normal file
3
src/store/types.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
interface IState {}
|
||||
|
||||
export { type IState };
|
||||
Loading…
Add table
Add a link
Reference in a new issue