chore: rename to template

This commit is contained in:
afiqzudinhadi 2025-06-19 16:51:10 +08:00
parent 063dfe39e9
commit c011186c37
46 changed files with 143 additions and 142 deletions

View file

@ -0,0 +1,4 @@
import { config } from "@repo/eslint-config";
/** @type {import("eslint").Linter.Config} */
export default config;

View file

@ -0,0 +1,41 @@
{
"name": "express-template",
"version": "0.0.0",
"type": "module",
"private": true,
"scripts": {
"start": "node dist/index.js",
"dev": "tsup --watch --onSuccess \"node dist/index.cjs\"",
"build": "tsup",
"check-types": "tsc --noEmit",
"lint": "eslint src/ --max-warnings 0",
"test": "jest --detectOpenHandles"
},
"jest": {
"preset": "@repo/jest-presets/node"
},
"dependencies": {
"@repo/logger": "*",
"body-parser": "^1.20.3",
"cors": "^2.8.5",
"express": "4.21.2",
"morgan": "^1.10.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@repo/eslint-config": "*",
"@repo/jest-presets": "*",
"@repo/typescript-config": "*",
"@types/body-parser": "^1.19.5",
"@types/cors": "^2.8.17",
"@types/express": "4.17.21",
"@types/morgan": "^1.9.9",
"@types/node": "^22.15.3",
"@types/supertest": "^6.0.2",
"eslint": "^9.29.0",
"jest": "^29.7.0",
"supertest": "^7.1.0",
"tsup": "^8.5.0",
"typescript": "5.8.2"
}
}

View file

@ -0,0 +1,23 @@
import supertest from "supertest";
import { describe, it, expect } from "@jest/globals";
import { createServer } from "../server";
describe("Server", () => {
it("health check returns 200", async () => {
await supertest(createServer())
.get("/status")
.expect(200)
.then((res) => {
expect(res.ok).toBe(true);
});
});
it("message endpoint says hello", async () => {
await supertest(createServer())
.get("/message/jared")
.expect(200)
.then((res) => {
expect(res.body).toEqual({ message: "hello jared" });
});
});
});

View file

@ -0,0 +1,9 @@
import { log } from "@repo/logger";
import { createServer } from "./server";
const port = process.env.PORT || 5001;
const server = createServer();
server.listen(port, () => {
log(`api running on ${port}`);
});

View file

@ -0,0 +1,22 @@
import { json, urlencoded } from "body-parser";
import express, { type Express } from "express";
import morgan from "morgan";
import cors from "cors";
export const createServer = (): Express => {
const app = express();
app
.disable("x-powered-by")
.use(morgan("dev"))
.use(urlencoded({ extended: true }))
.use(json())
.use(cors())
.get("/message/:name", (req, res) => {
return res.json({ message: `hello ${req.params.name}` });
})
.get("/status", (_, res) => {
return res.json({ ok: true });
});
return app;
};

View file

@ -0,0 +1,9 @@
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"lib": ["ES2015"],
"outDir": "./dist"
},
"exclude": ["node_modules"],
"include": ["."]
}

View file

@ -0,0 +1,8 @@
import { defineConfig, type Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: ["src/**/*"],
clean: true,
format: ["cjs"],
...options,
}));

View file

@ -0,0 +1,9 @@
{
"extends": ["//"],
"tasks": {
"build": {
"env": ["PORT"],
"outputs": ["dist/**"]
}
}
}