Skip to content

Commit

Permalink
feat: initialized bun express server
Browse files Browse the repository at this point in the history
  • Loading branch information
warmachine028 committed Oct 24, 2024
1 parent a293c40 commit f824f9e
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 7 deletions.
4 changes: 3 additions & 1 deletion client/eslint.config.ts → client/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default tseslint.config(
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }]
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'@typescript-eslint/no-empty-object-type': 'off',
'react-refresh/only-export-components': 'off'
}
}
)
6 changes: 3 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"dev": "bun x vite",
"build": "bun x vite build",
"lint": "eslint .",
"preview": "vite preview"
"preview": "bun x vite preview"
},
"dependencies": {
"@radix-ui/react-checkbox": "^1.1.2",
Expand Down
21 changes: 20 additions & 1 deletion client/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion client/src/api/posts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import { PostsResponse, Post } from '@/types'

const API_URL = 'https://dummyjson.com'
const API_URL = import.meta.env.VITE_API_URL

export const getPosts = async (skip: number = 0, limit: number = 10): Promise<PostsResponse> => {
try {
Expand Down
7 changes: 6 additions & 1 deletion client/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ export default defineConfig({
alias: {
'@': path.resolve(__dirname, './src')
}
},
build: {
chunkSizeWarningLimit: 1600
}
})
42 changes: 42 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel

**/*.trace
**/*.zip
**/*.tar.gz
**/*.tgz
**/*.log
package-lock.json
**/*.bun
15 changes: 15 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Elysia with Bun runtime

## Getting Started
To get started with this template, simply paste this command into your terminal:
```bash
bun create elysia ./elysia-example
```

## Development
To start the development server run:
```bash
bun run dev
```

Open http://localhost:3000/ with your browser to see the result.
Binary file added server/bun.lockb
Binary file not shown.
24 changes: 24 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "react-query-demo",
"version": "1.0.50",
"type": "module",
"scripts": {
"test": "bun --watch test",
"dev": "bun --watch src/index.ts",
"start": "bun run src/index.ts"
},
"dependencies": {
"@elysiajs/cors": "^1.1.1",
"@elysiajs/cron": "^1.1.1",
"@elysiajs/swagger": "^1.1.5",
"elysia": "latest"
},
"devDependencies": {
"bun-types": "latest"
},
"license": "MIT",
"peerDependencies": {
"typescript": "^5.6.3"
},
"module": "src/index.js"
}
Binary file added server/public/favicon.ico
Binary file not shown.
9 changes: 9 additions & 0 deletions server/src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type GetPostsParams = {
query: {
cursor: string
limit: number
}
}
export const getPosts = async ({ query: { cursor, limit } }: GetPostsParams) => {
console.log(cursor, limit)
}
44 changes: 44 additions & 0 deletions server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Elysia, t } from 'elysia'
import { swagger } from '@elysiajs/swagger'
import { cors } from '@elysiajs/cors'
import { cron } from '@elysiajs/cron'
import { postRoutes } from '@/routes'

const port = Bun.env.PORT || 5000

new Elysia()
.use(
// Create a cron job to ping the server every 14 minutes
cron({
name: 'Ping Server',
pattern: '*/14 * * * *',
async run() {
try {
const response = await fetch('https://react-query-demoo.vercel.app')
if (response.ok) {
console.log('Server pinged successfully')
} else {
console.error('Failed to ping server:', response.status, response.statusText)
}
} catch (error) {
console.error('Error pinging server:', error)
}
}
})
)
.use(cors())
.use(
swagger({
path: '/docs',
documentation: {
info: {
title: 'React Query Demo Documentation',
version: '1.0.0'
}
}
})
)
.get('/favicon.ico', () => Bun.file('public/favicon.ico'))
.get('/', () => '💾 Hello from React Query Demo server')
.use(postRoutes)
.listen(port, () => console.log(`🦊 Elysia is running at http://localhost:${port}`))
10 changes: 10 additions & 0 deletions server/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Elysia, t } from 'elysia'
import { getPosts } from '@/controllers'

export const postRoutes = new Elysia({ prefix: '/posts' }).get('/', getPosts, {
//
query: t.Object({
skip: t.Optional(t.String()),
limit: t.Optional(t.Number())
})
})
Loading

0 comments on commit f824f9e

Please sign in to comment.