# SvelteKit with Socket.IO Integration
+# SvelteKit with Socket.IO Integration
- + --
- {#each log as event}
-
- {event} - {/each} -
diff --git a/.prettierrc b/.prettierrc index 7ebb855..ffff96c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,15 +1,18 @@ { - "useTabs": true, - "singleQuote": true, - "trailingComma": "none", - "printWidth": 100, - "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"], - "overrides": [ - { - "files": "*.svelte", - "options": { - "parser": "svelte" - } - } - ] + "tabWidth": 2, + "printWidth": 150, + "useTabs": false, + "semi": true, + "singleQuote": true, + "trailingComma": "all", + "bracketSameLine": true, + "plugins": ["prettier-plugin-svelte"], + "overrides": [ + { + "files": "*.svelte", + "options": { + "parser": "svelte" + } + } + ] } diff --git a/README.md b/README.md index 414288f..d43604e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # SVChat + A is a simple chat app built with SvelteKit, Drizzle ORM, and PostgreSQL ## Techstack +  diff --git a/drizzle.config.ts b/drizzle.config.ts index 58c6b2f..31a3fe3 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -2,13 +2,13 @@ import { defineConfig } from 'drizzle-kit'; if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set'); export default defineConfig({ - schema: './src/lib/server/db/schema.ts', + schema: './src/lib/server/db/schema.ts', - dbCredentials: { - url: process.env.DATABASE_URL - }, + dbCredentials: { + url: process.env.DATABASE_URL, + }, - verbose: true, - strict: true, - dialect: 'postgresql' + verbose: true, + strict: true, + dialect: 'postgresql', }); diff --git a/eslint.config.js b/eslint.config.js index aa5987f..fc11e45 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -8,27 +8,27 @@ import ts from 'typescript-eslint'; const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url)); export default ts.config( - includeIgnoreFile(gitignorePath), - js.configs.recommended, - ...ts.configs.recommended, - ...svelte.configs['flat/recommended'], - prettier, - ...svelte.configs['flat/prettier'], - { - languageOptions: { - globals: { - ...globals.browser, - ...globals.node - } - } - }, - { - files: ['**/*.svelte'], + includeIgnoreFile(gitignorePath), + js.configs.recommended, + ...ts.configs.recommended, + ...svelte.configs['flat/recommended'], + prettier, + ...svelte.configs['flat/prettier'], + { + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + }, + }, + }, + { + files: ['**/*.svelte'], - languageOptions: { - parserOptions: { - parser: ts.parser - } - } - } + languageOptions: { + parserOptions: { + parser: ts.parser, + }, + }, + }, ); diff --git a/package.json b/package.json index a498d6d..cc9bf94 100644 --- a/package.json +++ b/package.json @@ -1,48 +1,48 @@ { - "name": "chatapp", - "private": true, - "version": "0.0.1", - "type": "module", - "scripts": { - "dev": "vite dev", - "build": "vite build", - "preview": "vite preview", - "start": "PORT=3005 tsm ./prodServer.ts", - "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", - "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "format": "prettier --write .", - "lint": "prettier --check . && eslint .", - "db:migrate": "drizzle-kit generate --config drizzle.config.ts && drizzle-kit push --config drizzle.config.ts", - "db:studio": "drizzle-kit studio" - }, - "devDependencies": { - "@eslint/compat": "^1.2.3", - "@sveltejs/adapter-node": "^5.2.11", - "@sveltejs/kit": "^2.0.0", - "@sveltejs/vite-plugin-svelte": "^4.0.0", - "autoprefixer": "^10.4.20", - "drizzle-kit": "^0.22.0", - "eslint": "^9.7.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-svelte": "^2.36.0", - "globals": "^15.0.0", - "prettier": "^3.3.2", - "prettier-plugin-svelte": "^3.2.6", - "prettier-plugin-tailwindcss": "^0.6.5", - "svelte": "^5.0.0", - "svelte-check": "^4.0.0", - "tailwindcss": "^3.4.9", - "typescript": "^5.0.0", - "typescript-eslint": "^8.0.0", - "vite": "^5.4.11" - }, - "dependencies": { - "daisyui": "^4.12.23", - "drizzle-orm": "^0.33.0", - "express": "^4.21.2", - "postgres": "^3.4.4", - "socket.io": "^4.8.1", - "socket.io-client": "^4.8.1", - "tsm": "^2.3.0" - } + "name": "chatapp", + "private": true, + "version": "0.0.1", + "type": "module", + "scripts": { + "dev": "vite dev", + "build": "vite build", + "preview": "vite preview", + "start": "PORT=3005 tsm ./prodServer.ts", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", + "format": "prettier --write .", + "lint": "prettier --check . && eslint .", + "db:migrate": "drizzle-kit generate --config drizzle.config.ts && drizzle-kit push --config drizzle.config.ts", + "db:studio": "drizzle-kit studio" + }, + "devDependencies": { + "@eslint/compat": "^1.2.3", + "@sveltejs/adapter-node": "^5.2.11", + "@sveltejs/kit": "^2.0.0", + "@sveltejs/vite-plugin-svelte": "^4.0.0", + "autoprefixer": "^10.4.20", + "drizzle-kit": "^0.22.0", + "eslint": "^9.7.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-svelte": "^2.36.0", + "globals": "^15.0.0", + "prettier": "^3.3.2", + "prettier-plugin-svelte": "^3.2.6", + "prettier-plugin-tailwindcss": "^0.6.5", + "svelte": "^5.0.0", + "svelte-check": "^4.0.0", + "tailwindcss": "^3.4.9", + "typescript": "^5.0.0", + "typescript-eslint": "^8.0.0", + "vite": "^5.4.11" + }, + "dependencies": { + "daisyui": "^4.12.23", + "drizzle-orm": "^0.33.0", + "express": "^4.21.2", + "postgres": "^3.4.4", + "socket.io": "^4.8.1", + "socket.io-client": "^4.8.1", + "tsm": "^2.3.0" + } } diff --git a/postcss.config.js b/postcss.config.js index 0f77216..2aa7205 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,6 +1,6 @@ export default { - plugins: { - tailwindcss: {}, - autoprefixer: {} - } + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, }; diff --git a/prodServer.ts b/prodServer.ts index 5a366ff..215b1ed 100644 --- a/prodServer.ts +++ b/prodServer.ts @@ -8,23 +8,23 @@ const server = createServer(app); const io = new Server(server); io.on('connection', (socket) => { - console.log(`[ws:kit] client connected (${socket.id})`); - io!.emit('message', `Hello from SvelteKit ${new Date().toLocaleString()} (${socket.id})`); + console.log(`[ws:kit] client connected (${socket.id})`); + io!.emit('message', `Hello from SvelteKit ${new Date().toLocaleString()} (${socket.id})`); - socket.on('disconnect', () => { - io!.emit('message', `client disconnected (${socket.id})`) - console.log(`[ws:kit] client disconnected (${socket.id})`); - }); + socket.on('disconnect', () => { + io!.emit('message', `client disconnected (${socket.id})`); + console.log(`[ws:kit] client disconnected (${socket.id})`); + }); }); app.use((req, res, next) => { - if (req.path.startsWith('/socket.io/')) { - next(); - } else { - handler(req, res); - } + if (req.path.startsWith('/socket.io/')) { + next(); + } else { + handler(req, res); + } }); server.listen(3005, () => { - console.log('Listening on http://0.0.0.0:3005'); -}); \ No newline at end of file + console.log('Listening on http://0.0.0.0:3005'); +}); diff --git a/src/app.d.ts b/src/app.d.ts index da08e6d..520c421 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,13 +1,13 @@ // See https://svelte.dev/docs/kit/types#app.d.ts // for information about these interfaces declare global { - namespace App { - // interface Error {} - // interface Locals {} - // interface PageData {} - // interface PageState {} - // interface Platform {} - } + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface PageState {} + // interface Platform {} + } } export {}; diff --git a/src/app.html b/src/app.html index 0103ada..40d2843 100644 --- a/src/app.html +++ b/src/app.html @@ -1,11 +1,11 @@ -
- - - - %sveltekit.head% - + + + + + %sveltekit.head% + - -