-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
82 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,7 @@ | ||
import { z } from 'zod'; | ||
|
||
const base = z.object({ | ||
export const envSchema = z.object({ | ||
NODE_ENV: z.enum(['development', 'production']).default('development'), | ||
}); | ||
const ci = base.extend({ | ||
CI: z.coerce.boolean().pipe(z.literal(true)), | ||
}); | ||
export type CiEnvModel = z.infer<typeof ci>; | ||
|
||
const local = base.extend({ | ||
CI: z.void(), | ||
CI: z.coerce.boolean().default(false), | ||
PORT: z.coerce.number().default(3000), | ||
}); | ||
export const envSchema = z.union([ci, local]); | ||
export type EnvModel = z.infer<typeof envSchema>; | ||
|
||
export function isCiEnv(env: EnvModel): env is CiEnvModel { | ||
return 'CI' in env; | ||
} | ||
|
||
export function isDevEnv(env: EnvModel): boolean { | ||
return env.NODE_ENV === 'development'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { envSchema } from '@/config/index.js'; | ||
import { homeModule } from '@/home/index.js'; | ||
import { sendNotFound } from '@/http/index.js'; | ||
import { postsModule } from '@/posts/index.js'; | ||
import { projectsModule } from '@/projects/index.js'; | ||
import { uiModule } from '@/ui/index.js'; | ||
import fastifyStatic from '@fastify/static'; | ||
import closeWithGrace from 'close-with-grace'; | ||
import consola from 'consola'; | ||
import Fastify from 'fastify'; | ||
import path from 'node:path'; | ||
import process from 'node:process'; | ||
|
||
consola.start('Initializing server...'); | ||
|
||
const env = envSchema.parse(process.env); | ||
|
||
const app = Fastify({ | ||
logger: true, | ||
ignoreTrailingSlash: true, | ||
}); | ||
|
||
await app.register(fastifyStatic, { | ||
root: path.resolve(process.cwd(), 'public'), | ||
}); | ||
|
||
await app.register(uiModule); | ||
await app.register(homeModule); | ||
await app.register(postsModule); | ||
await app.register(projectsModule); | ||
|
||
app.setNotFoundHandler(async (_, reply) => { | ||
return sendNotFound(reply); | ||
}); | ||
|
||
const closeListeners = closeWithGrace({ delay: 500 }, async function ({ err }) { | ||
if (err) { | ||
app.log.error(err); | ||
} | ||
await app.close(); | ||
}); | ||
|
||
app.addHook('onClose', (_, done) => { | ||
closeListeners.uninstall(); | ||
done(); | ||
}); | ||
|
||
app.listen({ port: env.PORT }, (err, address) => { | ||
if (err) { | ||
app.log.error(err); | ||
process.exit(1); | ||
} | ||
|
||
consola.success(`Server initialized on ${address}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,5 @@ | |
} | ||
}, | ||
"include": ["src"], | ||
"exclude": ["src/client.ts"] | ||
"exclude": ["src/client.ts", "src/**/*.spec.ts"] | ||
} |
Oops, something went wrong.