diff --git a/backend/.gitignore b/backend/.gitignore index 4602521..3a254f0 100755 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,6 +1,3 @@ node_modules # Keep environment variables out of version control -.env - -# Keep generated files out of version control -docs/api-doc.json \ No newline at end of file +.env \ No newline at end of file diff --git a/backend/app.js b/backend/app.js deleted file mode 100755 index 3d84e31..0000000 --- a/backend/app.js +++ /dev/null @@ -1,42 +0,0 @@ -import express from "express"; -import { initialize } from "express-openapi"; -import swaggerUi from "swagger-ui-express"; -import yamljs from "yamljs"; - -import eventsService from "./api/services/eventsService.js"; -import usersService from "./api/services/usersService.js"; - -// initialise openapi with express, serving api docs at '/api-docs-json' as json :( -const app = express(); - -// middleware -app.use(express.json()); - -const apiDoc = yamljs.load("./api/api-doc.yml"); -initialize({ - app, - apiDoc: apiDoc, - dependencies: { - eventsService: eventsService, - usersService: usersService, - }, - paths: "./api/paths", - docsPath: "/api-docs-json", -}); - -// convert from json and serve api docs with a pretty ui using swagger-ui :) -app.use( - "/api-docs", - swaggerUi.serve, - swaggerUi.setup(null, { - swaggerOptions: { - url: "/api-docs-json", - }, - }), -); - -app.listen(3000, () => { - console.log( - "Server running, API docs available at http://localhost:3000/api-docs", - ); -}); diff --git a/backend/app.ts b/backend/app.ts new file mode 100755 index 0000000..daf3a62 --- /dev/null +++ b/backend/app.ts @@ -0,0 +1,18 @@ +import express from 'express'; +import swaggerUi from 'swagger-ui-express'; +import * as fs from 'fs'; +import * as path from 'path'; + +const app = express(); +const port = 3000; + +// Load the OpenAPI document +const apiDocPath = path.resolve(__dirname, '../backend/docs/api_docs.json'); +const apiDoc = fs.readFileSync(apiDocPath, 'utf8'); + +// Serve the OpenAPI documentation +app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(JSON.parse(apiDoc))); + +app.listen(port, () => { + console.log(`Server is running at http://localhost:${port}`); +}); \ No newline at end of file diff --git a/backend/nodemon.json b/backend/nodemon.json new file mode 100644 index 0000000..aa96130 --- /dev/null +++ b/backend/nodemon.json @@ -0,0 +1,5 @@ +{ + "watch": ["src"], + "ext": "ts", + "exec": "ts-node ./app.ts" + } \ No newline at end of file diff --git a/backend/package.json b/backend/package.json index d029f54..d4e79b6 100755 --- a/backend/package.json +++ b/backend/package.json @@ -1,11 +1,10 @@ { "name": "aspa-backend", - "version": "1.0.0", + "version": "2.0.0", "description": "The backend for the aspa project", - "main": "index.js", - "type": "module", + "main": "app.ts", "scripts": { - "dev": "npx prisma migrate dev && nodemon app.js", + "dev": "nodemon", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", diff --git a/package.json b/package.json index 81fa485..a9d8f29 100755 --- a/package.json +++ b/package.json @@ -22,7 +22,9 @@ "description": "", "dependencies": { "@next/font": "^14.2.4", - "@openapitools/openapi-generator-cli": "^2.13.4" + "@openapitools/openapi-generator-cli": "^2.13.4", + "@types/express": "^4.17.21", + "@types/swagger-ui-express": "^4.1.6" }, "devDependencies": { "husky": "^9.1.4" diff --git a/yarn.lock b/yarn.lock index ee6b979..64fce92 100755 --- a/yarn.lock +++ b/yarn.lock @@ -78,6 +78,93 @@ rxjs "7.8.1" tslib "2.6.2" +"@types/body-parser@*": + version "1.19.5" + resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.5.tgz#04ce9a3b677dc8bd681a17da1ab9835dc9d3ede4" + integrity sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg== + dependencies: + "@types/connect" "*" + "@types/node" "*" + +"@types/connect@*": + version "3.4.38" + resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.38.tgz#5ba7f3bc4fbbdeaff8dded952e5ff2cc53f8d858" + integrity sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug== + dependencies: + "@types/node" "*" + +"@types/express-serve-static-core@^4.17.33": + version "4.19.5" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.19.5.tgz#218064e321126fcf9048d1ca25dd2465da55d9c6" + integrity sha512-y6W03tvrACO72aijJ5uF02FRq5cgDR9lUxddQ8vyF+GvmjJQqbzDcJngEjURc+ZsG31VI3hODNZJ2URj86pzmg== + dependencies: + "@types/node" "*" + "@types/qs" "*" + "@types/range-parser" "*" + "@types/send" "*" + +"@types/express@*", "@types/express@^4.17.21": + version "4.17.21" + resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.21.tgz#c26d4a151e60efe0084b23dc3369ebc631ed192d" + integrity sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ== + dependencies: + "@types/body-parser" "*" + "@types/express-serve-static-core" "^4.17.33" + "@types/qs" "*" + "@types/serve-static" "*" + +"@types/http-errors@*": + version "2.0.4" + resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-2.0.4.tgz#7eb47726c391b7345a6ec35ad7f4de469cf5ba4f" + integrity sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA== + +"@types/mime@^1": + version "1.3.5" + resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.5.tgz#1ef302e01cf7d2b5a0fa526790c9123bf1d06690" + integrity sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w== + +"@types/node@*": + version "22.1.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.1.0.tgz#6d6adc648b5e03f0e83c78dc788c2b037d0ad94b" + integrity sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw== + dependencies: + undici-types "~6.13.0" + +"@types/qs@*": + version "6.9.15" + resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.15.tgz#adde8a060ec9c305a82de1babc1056e73bd64dce" + integrity sha512-uXHQKES6DQKKCLh441Xv/dwxOq1TVS3JPUMlEqoEglvlhR6Mxnlew/Xq/LRVHpLyk7iK3zODe1qYHIMltO7XGg== + +"@types/range-parser@*": + version "1.2.7" + resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb" + integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ== + +"@types/send@*": + version "0.17.4" + resolved "https://registry.yarnpkg.com/@types/send/-/send-0.17.4.tgz#6619cd24e7270793702e4e6a4b958a9010cfc57a" + integrity sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA== + dependencies: + "@types/mime" "^1" + "@types/node" "*" + +"@types/serve-static@*": + version "1.15.7" + resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.15.7.tgz#22174bbd74fb97fe303109738e9b5c2f3064f714" + integrity sha512-W8Ym+h8nhuRwaKPaDw34QUkwsGi6Rc4yYqvKFo5rm2FUEhCFbzVWrxXUxuKK8TASjWsysJY0nsmNCGhCOIsrOw== + dependencies: + "@types/http-errors" "*" + "@types/node" "*" + "@types/send" "*" + +"@types/swagger-ui-express@^4.1.6": + version "4.1.6" + resolved "https://registry.yarnpkg.com/@types/swagger-ui-express/-/swagger-ui-express-4.1.6.tgz#d0929e3fabac1a96a8a9c6c7ee8d42362c5cdf48" + integrity sha512-UVSiGYXa5IzdJJG3hrc86e8KdZWLYxyEsVoUI4iPXc7CO4VZ3AfNP8d/8+hrDRIqz+HAaSMtZSqAsF3Nq2X/Dg== + dependencies: + "@types/express" "*" + "@types/serve-static" "*" + agent-base@^7.0.2: version "7.1.1" resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-7.1.1.tgz#bdbded7dfb096b751a2a087eeeb9664725b2e317" @@ -729,6 +816,11 @@ uid@2.0.2: dependencies: "@lukeed/csprng" "^1.0.0" +undici-types@~6.13.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.13.0.tgz#e3e79220ab8c81ed1496b5812471afd7cf075ea5" + integrity sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg== + universalify@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.1.tgz#168efc2180964e6386d061e094df61afe239b18d"