Skip to content

Commit 40db0a0

Browse files
committed
feat(api): setup
1 parent 2a4df59 commit 40db0a0

File tree

7 files changed

+2484
-39
lines changed

7 files changed

+2484
-39
lines changed

package-lock.json

Lines changed: 2401 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

packages/api/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "api",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "tsx src/server.ts",
8+
"dev": "tsx src/server.ts --watch",
9+
"test": "vitest",
10+
"build": "tsup"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"dependencies": {
16+
"fastify": "^4.12.0"
17+
},
18+
"devDependencies": {
19+
"tsup": "^6.5.0",
20+
"tsx": "^3.12.2",
21+
"vitest": "^0.28.4"
22+
}
23+
}

packages/api/server.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test, expect } from 'vitest'
2+
3+
test('server.ts', async () => {
4+
expect(1).toBe(1)
5+
})

packages/api/server.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Fastify, { FastifyInstance, RouteShorthandOptions } from 'fastify'
2+
3+
const server: FastifyInstance = Fastify({})
4+
5+
const opts: RouteShorthandOptions = {
6+
schema: {
7+
response: {
8+
200: {
9+
type: 'object',
10+
properties: {
11+
message: {
12+
type: 'string',
13+
},
14+
},
15+
},
16+
},
17+
},
18+
}
19+
20+
server.get('/', opts, async () => {
21+
return { message: 'Hello word!' }
22+
})
23+
24+
const start = async () => {
25+
try {
26+
await server.listen({ port: 3000 })
27+
28+
const address = server.server.address()
29+
30+
const port = typeof address === 'string' ? address : address?.port
31+
32+
console.log(`Server listening on port http://localhost:${port}`)
33+
} catch (err) {
34+
server.log.error(err)
35+
process.exit(1)
36+
}
37+
}
38+
start()

packages/api/tsup.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'tsup'
2+
3+
export default defineConfig({
4+
entry: ['server.ts'],
5+
splitting: false,
6+
sourcemap: true,
7+
clean: true,
8+
})

packages/api/vitest.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
watch: false,
6+
reporters: 'verbose',
7+
},
8+
})

0 commit comments

Comments
 (0)