init repo
This commit is contained in:
commit
964184851f
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
dist
|
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
dist
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
# fastify-ts-template
|
||||
|
||||
A template for fasitify with TypeScript, eslint and prettier built with esbuild.
|
||||
|
||||
## Using this template
|
||||
|
||||
`git clone` this repo, then delete the `.git` directory and initalize it again, and change `name` and `author` in `package.json`.
|
||||
|
||||
## License
|
||||
|
||||
The template itself is `GPL-3.0-only`, and it is a default recommended license for all projects created with this template, but projects are free to choose any other license.
|
|
@ -0,0 +1,24 @@
|
|||
// @ts-check
|
||||
|
||||
import tse from 'typescript-eslint';
|
||||
|
||||
export default tse.config(...tse.configs.recommended, {
|
||||
rules: {
|
||||
'no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
argsIgnorePattern: '_',
|
||||
args: 'after-used',
|
||||
caughtErrors: 'none',
|
||||
},
|
||||
],
|
||||
'no-invalid-regexp': 'error',
|
||||
'no-var': 'error',
|
||||
eqeqeq: 'error',
|
||||
'no-useless-concat': 'error',
|
||||
'no-useless-rename': 'error',
|
||||
'no-useless-assignment': 'error',
|
||||
'default-case': 'error',
|
||||
'prefer-const': 'error',
|
||||
},
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "fastify-ts-template",
|
||||
"license": "GPL-3.0-only",
|
||||
"author": "blek! <me@blek.codes>",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"dependencies": {
|
||||
"fastify": "^4.27.0",
|
||||
"typescript-eslint": "^7.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/eslint": "^8.56.10",
|
||||
"@types/node": "^20.12.11",
|
||||
"esbuild": "^0.21.1",
|
||||
"eslint": "^9.2.0",
|
||||
"prettier": "3.2.5",
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node scripts/build.js",
|
||||
"lint": "eslint",
|
||||
"format": "prettier"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
/**
|
||||
* @type { import("prettier").Config }
|
||||
*/
|
||||
export default {
|
||||
trailingComma: 'all',
|
||||
tabWidth: 4,
|
||||
semi: true,
|
||||
singleQuote: true,
|
||||
endOfLine: 'lf'
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
import esbuild from 'esbuild';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const entryPoints = fs
|
||||
.readdirSync('src', { recursive: true })
|
||||
.filter((x) => x.endsWith('.ts'))
|
||||
.map((x) => 'src/' + x);
|
||||
|
||||
if (fs.existsSync('dist')) fs.rmSync('dist', { recursive: true, force: true });
|
||||
|
||||
try {
|
||||
fs.mkdirSync('dist');
|
||||
} catch (_) {}
|
||||
|
||||
await esbuild.build({
|
||||
entryPoints,
|
||||
outdir: 'dist',
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
import Fastify from 'fastify';
|
||||
import routes from './routes/index.js';
|
||||
|
||||
const fastify = Fastify();
|
||||
|
||||
// register any plugins here, i.e.
|
||||
// fastify.register(middie);
|
||||
|
||||
fastify.register(routes);
|
||||
|
||||
fastify.listen({
|
||||
port: parseInt(process.env.PORT ?? '80'),
|
||||
host: process.env.HOST ?? 'localhost',
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
import { FastifyPluginAsync } from 'fastify';
|
||||
import ping from './ping.js';
|
||||
|
||||
export default (async function (fastify) {
|
||||
await fastify.register(ping);
|
||||
} as FastifyPluginAsync);
|
|
@ -0,0 +1,7 @@
|
|||
import { FastifyPluginAsync } from 'fastify';
|
||||
|
||||
export default (async function (fastify) {
|
||||
fastify.get('/ping', async () => {
|
||||
return 'Pong!';
|
||||
});
|
||||
} as FastifyPluginAsync);
|
Loading…
Reference in New Issue