diff --git a/backend/.gitignore b/backend/.gitignore
index 8f00ef2..8983a48 100644
--- a/backend/.gitignore
+++ b/backend/.gitignore
@@ -1,3 +1,4 @@
node_modules
.env
+.env.prod
dist
\ No newline at end of file
diff --git a/backend/src/config.ts b/backend/src/config.ts
index 02da315..4f33156 100644
--- a/backend/src/config.ts
+++ b/backend/src/config.ts
@@ -1,13 +1,28 @@
import dotenv from "dotenv";
-dotenv.config();
-
-export const PORT: number = parseInt(process.env.PORT || "8080", 10);
-export const MONGODB_URI: string =
- process.env.MONGODB_URI || "mongodb://localhost:27017/suriya";
-export const API_VERSION: string = process.env.API_VERSION || "1.5.5";
-export const PASSPORT_SECRET: string = "nodeauthsecret";
-export const config = {
+dotenv.config({});
+
+const baseConfig = {
+ PORT: parseInt(process.env.PORT || "8080", 10),
+ API_VERSION: process.env.API_VERSION || "1.5.5",
+ PASSPORT_SECRET: "nodeauthsecret",
jwtSecret: "JWT Secret",
jwtSession: { session: false },
};
+let envConfig;
+switch (process.env.PROD_ENV) {
+ case "prod":
+ envConfig = {
+ MONGODB_URI: process.env.MONGODB_URI_PROD,
+ };
+ break;
+ default:
+ envConfig = {
+ MONGODB_URI:
+ process.env.MONGODB_URI || "mongodb://localhost:27017/suriya",
+ };
+}
+
+const config = { ...baseConfig, ...envConfig };
+
+export default config;
diff --git a/backend/src/controller/accountController.ts b/backend/src/controller/accountController.ts
index 4b10d59..0540973 100644
--- a/backend/src/controller/accountController.ts
+++ b/backend/src/controller/accountController.ts
@@ -1,10 +1,9 @@
import { Request, Response } from "express";
import { UserModel } from "../models/Users";
import jwt from "jwt-simple";
-import { config } from "../config";
+import config from "../config";
import mongoose from "mongoose";
import { Status } from "../models/Status";
-import { API_VERSION } from "../config";
export default {
login: async (req: Request, res: Response) => {
@@ -61,7 +60,7 @@ export default {
res.json({
message: "Status retrieved successfully",
status: { db: dbStatus },
- api_version: API_VERSION,
+ api_version: config.API_VERSION,
user: {
username,
id: _id,
diff --git a/backend/src/db.ts b/backend/src/db.ts
index 9d3c535..22bff97 100644
--- a/backend/src/db.ts
+++ b/backend/src/db.ts
@@ -1,13 +1,13 @@
import mongoose from "mongoose";
-import { PORT, MONGODB_URI, API_VERSION } from "./config";
+import config from "./config";
import { Status } from "./models/Status";
const connectToDB = async () => {
try {
- const instance = await mongoose.connect(MONGODB_URI);
+ const instance = await mongoose.connect(config.MONGODB_URI);
console.log("Connected to MongoDB");
- const status = new Status({ db: true, version: "1.0.0" });
+ const status = new Status({ db: true, version: config.API_VERSION });
await Status.createCollection();
const session = await instance.startSession();
diff --git a/backend/src/index.ts b/backend/src/index.ts
index 425506f..2ff284b 100644
--- a/backend/src/index.ts
+++ b/backend/src/index.ts
@@ -2,7 +2,7 @@ import express, { Request, Response } from "express";
import bodyParser from "body-parser";
import cors from "cors";
import connectToDB from "./db";
-import { PORT, PASSPORT_SECRET } from "./config";
+import config from "./config";
import passport from "passport";
import { Strategy as LocalStrategy } from "passport-local";
import { UserModel } from "./models/Users";
@@ -31,7 +31,7 @@ app.get("/corstest", (req: Request, res: Response) => {
app.use(
session({
- secret: PASSPORT_SECRET,
+ secret: config.PASSPORT_SECRET,
resave: false,
saveUninitialized: false,
})
@@ -48,6 +48,6 @@ app.use("/", statusRoutes);
app.use("/", linkRoutes);
//Express-Server
-app.listen(PORT, () => {
- console.log(`Server is running on port ${PORT}`);
+app.listen(config.PORT, () => {
+ console.log(`Server is running on port ${config.PORT}`);
});
diff --git a/backend/src/middleware/auth.ts b/backend/src/middleware/auth.ts
index c9db3e8..c146149 100644
--- a/backend/src/middleware/auth.ts
+++ b/backend/src/middleware/auth.ts
@@ -5,7 +5,7 @@ import {
} from "passport-jwt";
import passport from "passport";
import { UserModel, User } from "../models/Users";
-import { config } from "../config";
+import config from "../config";
const jwtOptions: StrategyOptions = {
//Authorization: Bearer in request headers
diff --git a/frontend/.gitignore b/frontend/.gitignore
index cfa7514..a6dd390 100644
--- a/frontend/.gitignore
+++ b/frontend/.gitignore
@@ -13,7 +13,7 @@ dist
dist-ssr
coverage
*.local
-
+.env
/cypress/videos/
/cypress/screenshots/
diff --git a/frontend/cypress.config.ts b/frontend/cypress.config.ts
index f5a7e44..e80e0e1 100644
--- a/frontend/cypress.config.ts
+++ b/frontend/cypress.config.ts
@@ -3,6 +3,6 @@ import { defineConfig } from 'cypress'
export default defineConfig({
e2e: {
specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}',
- baseUrl: 'http://localhost:4000'
+ baseUrl: process.env.CYPRESS_BASE_URL
}
})
diff --git a/frontend/cypress/cypress.config.js b/frontend/cypress/cypress.config.js
new file mode 100644
index 0000000..97f47c4
--- /dev/null
+++ b/frontend/cypress/cypress.config.js
@@ -0,0 +1,9 @@
+const { defineConfig } = require("cypress");
+
+module.exports = defineConfig({
+ e2e: {
+ setupNodeEvents(on, config) {
+ // implement node event listeners here
+ },
+ },
+});
diff --git a/frontend/cypress/cypress/fixtures/example.json b/frontend/cypress/cypress/fixtures/example.json
new file mode 100644
index 0000000..02e4254
--- /dev/null
+++ b/frontend/cypress/cypress/fixtures/example.json
@@ -0,0 +1,5 @@
+{
+ "name": "Using fixtures to represent data",
+ "email": "hello@cypress.io",
+ "body": "Fixtures are a great way to mock data for responses to routes"
+}
diff --git a/frontend/cypress/cypress/support/commands.js b/frontend/cypress/cypress/support/commands.js
new file mode 100644
index 0000000..66ea16e
--- /dev/null
+++ b/frontend/cypress/cypress/support/commands.js
@@ -0,0 +1,25 @@
+// ***********************************************
+// This example commands.js shows you how to
+// create various custom commands and overwrite
+// existing commands.
+//
+// For more comprehensive examples of custom
+// commands please read more here:
+// https://on.cypress.io/custom-commands
+// ***********************************************
+//
+//
+// -- This is a parent command --
+// Cypress.Commands.add('login', (email, password) => { ... })
+//
+//
+// -- This is a child command --
+// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
+//
+//
+// -- This is a dual command --
+// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
+//
+//
+// -- This will overwrite an existing command --
+// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
\ No newline at end of file
diff --git a/frontend/cypress/cypress/support/e2e.js b/frontend/cypress/cypress/support/e2e.js
new file mode 100644
index 0000000..0e7290a
--- /dev/null
+++ b/frontend/cypress/cypress/support/e2e.js
@@ -0,0 +1,20 @@
+// ***********************************************************
+// This example support/e2e.js is processed and
+// loaded automatically before your test files.
+//
+// This is a great place to put global configuration and
+// behavior that modifies Cypress.
+//
+// You can change the location of this file or turn off
+// automatically serving support files with the
+// 'supportFile' configuration option.
+//
+// You can read more here:
+// https://on.cypress.io/configuration
+// ***********************************************************
+
+// Import commands.js using ES2015 syntax:
+import './commands'
+
+// Alternatively you can use CommonJS syntax:
+// require('./commands')
\ No newline at end of file
diff --git a/frontend/cypress/e2e/tsconfig.json b/frontend/cypress/e2e/tsconfig.json
index 37748fe..12b2725 100644
--- a/frontend/cypress/e2e/tsconfig.json
+++ b/frontend/cypress/e2e/tsconfig.json
@@ -2,6 +2,7 @@
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["./**/*", "../support/**/*"],
"compilerOptions": {
+ "baseUrl": "./",
"isolatedModules": false,
"target": "es5",
"lib": ["es5", "dom"],
diff --git a/frontend/env.d.ts b/frontend/env.d.ts
index 11f02fe..51c9d4d 100644
--- a/frontend/env.d.ts
+++ b/frontend/env.d.ts
@@ -1 +1,9 @@
///
+interface ImportMetaEnv {
+ readonly VITE_API_URL: string
+ // more env variables...
+}
+
+interface ImportMeta {
+ readonly env: ImportMetaEnv
+}
diff --git a/frontend/package.json b/frontend/package.json
index e2048df..acd60cc 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -4,16 +4,18 @@
"private": true,
"scripts": {
"build": "run-p type-check build-only",
+ "cypress:open": "cypress open",
+ "cypress:run": "cypress run --e2e",
"test:unit": "vitest",
- "test:e2e": "start-server-and-test preview http://localhost:4000 'cypress run --e2e'",
+ "test:e2e": "start-server-and-test preview 'cypress run --e2e'",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"build-only": "vite build",
"build-storybook": "storybook build",
- "dev": "vite",
+ "dev": "vite ",
"format": "prettier --write src/",
- "preview": "vite preview --host --port 4000",
+ "preview": "vite preview --host ",
"storybook": "storybook dev -p 6006",
- "test:e2e:dev": "start-server-and-test 'vite dev --port 4000' http://localhost:4000 'cypress open --e2e'",
+ "test:e2e:dev": "start-server-and-test 'vite dev --host' $VITE_DEV_SERVER_URL 'cypress open --e2e'",
"type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false"
},
"dependencies": {
diff --git a/frontend/src/components/BasisHeader.vue b/frontend/src/components/BasisHeader.vue
index ab7a8b3..d971236 100644
--- a/frontend/src/components/BasisHeader.vue
+++ b/frontend/src/components/BasisHeader.vue
@@ -25,6 +25,7 @@