Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielzxccc committed Oct 10, 2023
0 parents commit 10744bd
Show file tree
Hide file tree
Showing 8 changed files with 1,295 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"semi": false,
"tabWidth": 2
}
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node dist/index.js",
"dev": "nodemon src/index.ts",
"codegen": "kysely-codegen --dialect postgres"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2",
"kysely": "^0.26.3",
"pg": "^8.11.3",
"socket.io": "^4.7.2",
"ts-node": "^10.9.1"
},
"devDependencies": {
"@types/express": "^4.17.18",
"@types/pg": "^8.10.4",
"dotenv": "^16.3.1",
"kysely-codegen": "^0.10.1",
"nodemon": "^3.0.1",
"typescript": "^5.2.2",
"zod": "^3.22.4"
}
}
20 changes: 20 additions & 0 deletions src/config/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Kysely, PostgresDialect } from 'kysely'
import { DB } from 'kysely-codegen'
import { Pool } from 'pg'
import * as dotenv from 'dotenv'

dotenv.config()

export const db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({
connectionString: process.env.DATABASE_URL,
}),
}),
// log(event) {
// if (event.level === 'query') {
// console.log(event.query.sql)
// console.log(event.query.parameters)
// }
// },
})
12 changes: 12 additions & 0 deletions src/controllers/SocketController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { io } from '../index'

export function startSocket() {
io.on('connection', (socket) => {
console.log(socket.id)

socket.on('message', (socket) => {
console.log(socket)
io.emit('message', 'test')
})
})
}
25 changes: 25 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import express, { Express } from 'express'
import { createServer } from 'http'
import { Server } from 'socket.io'
import * as dotenv from 'dotenv'
import { startSocket } from './controllers/SocketController'
dotenv.config()

// routers

const app = express()
const httpServer = createServer(app)
const io = new Server(httpServer)

app.use(express.urlencoded({ extended: false }))
app.use(express.json())

app.use('/hello', (req, res) => {
res.send('hello')
})

startSocket()

httpServer.listen(3000, () => console.log('Server is running on port 3000'))

export { io }
29 changes: 29 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"sourceMap": true,
"outDir": "dist",
"allowJs": true,
"lib": ["dom", "es6"],
"baseUrl": "./src",
"paths": {
"@/*": [
"./*"
]
}
},
"exclude": [
"node_modules",
"dist"
],
"include": [
"src/**/*.ts",
"tests/**/*.spec.ts"
],
"files": [
"src/index.ts"
]
}
Loading

0 comments on commit 10744bd

Please sign in to comment.