From e3f9fa4cb92b5efae6e057ed98ed7cb248f44400 Mon Sep 17 00:00:00 2001 From: Ernie1234 Date: Wed, 5 Mar 2025 21:17:32 +0100 Subject: [PATCH 1/8] feat: add Render configuration for MongoDB and Node.js web service --- render.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 render.yaml diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..58849fe --- /dev/null +++ b/render.yaml @@ -0,0 +1,20 @@ +services: + mongo: + type: 'database' # Using Render's managed database service + name: 'shortit-mongo' + plan: 'free' # Choose your plan based on your needs + env: 'mongodb' + databaseUrl: 'mongodb://:@:/' # Placeholder, see below for details + + server: + type: 'webservice' # Define the service as a web service + name: 'shortit-server' + env: 'node' # Specify the Node.js environment + buildCommand: 'npm install && npm run build' # Install dependencies and build the project + startCommand: 'npm start' # Start the server + envVars: + MONGO_URI: 'mongodb://shortit-mongo:27017' # Connection string for MongoDB + MONGO_USERNAME: ${MONGO_USERNAME} # Reference environment variables from Render dashboard + MONGO_PASSWORD: ${MONGO_PASSWORD} # Reference environment variables from Render dashboard + plan: 'free' # Choose your plan + servicePort: 8000 # Port your service runs on From a5e896eb285e6b81dca091bd3f34793c16e1ddfd Mon Sep 17 00:00:00 2001 From: Ernie1234 Date: Wed, 5 Mar 2025 21:28:45 +0100 Subject: [PATCH 2/8] feat: replace docker-compose.yml with compose.yml for improved configuration --- docker-compose.yml => compose.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docker-compose.yml => compose.yml (100%) diff --git a/docker-compose.yml b/compose.yml similarity index 100% rename from docker-compose.yml rename to compose.yml From 1a2e0f7ba67bee5e3c97556018080451e95ae20c Mon Sep 17 00:00:00 2001 From: Ernie1234 Date: Wed, 11 Jun 2025 22:28:46 +0100 Subject: [PATCH 3/8] feat: copy the whole folder to docker --- Dockerfile | 15 +++++++++++---- compose.yml | 3 ++- render.yaml | 20 -------------------- src/index.ts | 3 +++ 4 files changed, 16 insertions(+), 25 deletions(-) delete mode 100644 render.yaml diff --git a/Dockerfile b/Dockerfile index 84f5395..e609a3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,19 @@ FROM node:alpine WORKDIR /usr/app -COPY package*.json . +# Copy package files +COPY package*.json ./ +# Install dependencies RUN npm ci -COPY . . +# Copy tsconfig and source files +COPY tsconfig.json ./ +COPY src/ ./src/ -RUN npm run build +# Build the application +RUN npm run build -CMD ["node", "dist/index.js"] +EXPOSE 8000 + +CMD ["npm", "start"] \ No newline at end of file diff --git a/compose.yml b/compose.yml index b24bc9b..10dd9d7 100644 --- a/compose.yml +++ b/compose.yml @@ -26,4 +26,5 @@ services: ports: - 8000:8000 volumes: - - ./src:/usr/app/src + - .:/usr/app + - /usr/app/node_modules diff --git a/render.yaml b/render.yaml deleted file mode 100644 index 58849fe..0000000 --- a/render.yaml +++ /dev/null @@ -1,20 +0,0 @@ -services: - mongo: - type: 'database' # Using Render's managed database service - name: 'shortit-mongo' - plan: 'free' # Choose your plan based on your needs - env: 'mongodb' - databaseUrl: 'mongodb://:@:/' # Placeholder, see below for details - - server: - type: 'webservice' # Define the service as a web service - name: 'shortit-server' - env: 'node' # Specify the Node.js environment - buildCommand: 'npm install && npm run build' # Install dependencies and build the project - startCommand: 'npm start' # Start the server - envVars: - MONGO_URI: 'mongodb://shortit-mongo:27017' # Connection string for MongoDB - MONGO_USERNAME: ${MONGO_USERNAME} # Reference environment variables from Render dashboard - MONGO_PASSWORD: ${MONGO_PASSWORD} # Reference environment variables from Render dashboard - plan: 'free' # Choose your plan - servicePort: 8000 # Port your service runs on diff --git a/src/index.ts b/src/index.ts index 325d355..57a4379 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,9 +19,12 @@ app.get('/', (req: Request, res: Response) => { }); app.use('/api/v1', urlRoute); + const start = async () => { try { + console.log("DATABASE URL here: ",process.env.DATABASE_URL) await connectDb(process.env.DATABASE_URL || ''); + app.listen(port, () => { logger.info(`Server is started at port: http://localhost:${port}`); }); From 497ce31929572cd630f76842eb2b44725828dce3 Mon Sep 17 00:00:00 2001 From: Ernie1234 Date: Wed, 11 Jun 2025 22:47:55 +0100 Subject: [PATCH 4/8] fix: apply linting fixes --- src/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 57a4379..209c2f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,10 +19,8 @@ app.get('/', (req: Request, res: Response) => { }); app.use('/api/v1', urlRoute); - const start = async () => { try { - console.log("DATABASE URL here: ",process.env.DATABASE_URL) await connectDb(process.env.DATABASE_URL || ''); app.listen(port, () => { From dc940f8f38f570f0c0b0d5a16bf9f4ee2a2ac924 Mon Sep 17 00:00:00 2001 From: Ernie1234 Date: Thu, 12 Jun 2025 00:03:49 +0100 Subject: [PATCH 5/8] fix: remove volumes --- compose.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compose.yml b/compose.yml index 10dd9d7..fcedee2 100644 --- a/compose.yml +++ b/compose.yml @@ -10,8 +10,8 @@ services: environment: - MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME} - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD} - volumes: - - ./data:/data/db + # volumes: + # - ./data:/data/db server: container_name: 'shortit-server' build: @@ -25,6 +25,6 @@ services: - ${PORT} ports: - 8000:8000 - volumes: - - .:/usr/app - - /usr/app/node_modules + # volumes: + # - .:/usr/app + # - /usr/app/node_modules From 3af7552dfe64223b01c106aa9b8ffb5dabcf4dbb Mon Sep 17 00:00:00 2001 From: Ernie1234 Date: Thu, 12 Jun 2025 00:13:57 +0100 Subject: [PATCH 6/8] fix: change main directory --- package.json | 2 +- tsconfig.json | 113 ++++---------------------------------------------- 2 files changed, 9 insertions(+), 106 deletions(-) diff --git a/package.json b/package.json index 4bc3331..41f6548 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "shortit", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "jest", "build": "npx tsc", diff --git a/tsconfig.json b/tsconfig.json index 298f68b..e6d9aa5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,110 +1,13 @@ { "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - - /* Projects */ - // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ - // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ - - /* Modules */ - "module": "CommonJS", /* Specify what module code is generated. */ - "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ - // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ - // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ - // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ - // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ - // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ - - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - "outDir": "./dist", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ - // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "target": "es2016", + "module": "CommonJS", + "rootDir": "./", + "outDir": "./dist", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, "strictPropertyInitialization": false }, "include": ["src/**/*", "jest.config.ts"], From 0b42debc451edbd7ef54abab75360d6c7d1fecc8 Mon Sep 17 00:00:00 2001 From: Ernie1234 Date: Thu, 12 Jun 2025 00:21:09 +0100 Subject: [PATCH 7/8] fix: change the rootdir --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index e6d9aa5..28b00ec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "es2016", "module": "CommonJS", - "rootDir": "./", + "rootDir": "./src", "outDir": "./dist", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, From dba3d8f6bc7e0a305c5421f2c6b0ffe7292fea05 Mon Sep 17 00:00:00 2001 From: Ernie1234 Date: Thu, 12 Jun 2025 00:25:49 +0100 Subject: [PATCH 8/8] fix: remove jest from tsconfig.json include --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 28b00ec..c4623cf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,6 @@ "skipLibCheck": true, "strictPropertyInitialization": false }, - "include": ["src/**/*", "jest.config.ts"], + "include": ["src/**/*"], "exclude": ["node_modules", "dist"] }