chore: rename to template
This commit is contained in:
parent
063dfe39e9
commit
c011186c37
46 changed files with 143 additions and 142 deletions
23
apps/express-template/src/__tests__/server.test.ts
Normal file
23
apps/express-template/src/__tests__/server.test.ts
Normal 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" });
|
||||
});
|
||||
});
|
||||
});
|
||||
9
apps/express-template/src/index.ts
Normal file
9
apps/express-template/src/index.ts
Normal 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}`);
|
||||
});
|
||||
22
apps/express-template/src/server.ts
Normal file
22
apps/express-template/src/server.ts
Normal 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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue