From 3475b3863c85ee1b22f55dab0ed552467523378f Mon Sep 17 00:00:00 2001 From: kimatata <117462761+kimatata@users.noreply.github.com> Date: Sun, 25 May 2025 10:13:57 +0900 Subject: [PATCH] chore: db file compatibility (#228) --- backend/config/config.js | 4 ++-- backend/server.js | 14 ++++++++++++-- docker-compose.yaml | 2 +- e2e/index.spec.ts | 6 ------ e2e/not-demo-mode.spec.ts | 12 ++++++++++++ 5 files changed, 27 insertions(+), 11 deletions(-) delete mode 100644 e2e/index.spec.ts create mode 100644 e2e/not-demo-mode.spec.ts diff --git a/backend/config/config.js b/backend/config/config.js index 790e93b..d514651 100644 --- a/backend/config/config.js +++ b/backend/config/config.js @@ -1,6 +1,6 @@ const path = require('path'); -const databasePath = path.resolve(__dirname, '../../database/database.sqlite'); +const databasePath = path.resolve(__dirname, '../database/database.sqlite'); module.exports = { development: { @@ -14,5 +14,5 @@ module.exports = { production: { dialect: 'sqlite', storage: databasePath, - } + }, }; diff --git a/backend/server.js b/backend/server.js index cedb785..99270c6 100644 --- a/backend/server.js +++ b/backend/server.js @@ -1,9 +1,18 @@ +const path = require('path'); const express = require('express'); const RateLimit = require('express-rate-limit'); -const path = require('path'); const { Sequelize } = require('sequelize'); const app = express(); +// enable frontend access +const cors = require('cors'); +const frontendOrigin = process.env.FRONTEND_ORIGIN || 'http://localhost:8000'; +const corsOptions = { + origin: frontendOrigin, + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', +}; +app.use(cors(corsOptions)); + // enable json middleware app.use(express.json()); @@ -19,9 +28,10 @@ app.use(limiter); app.use(express.static(path.join(__dirname, 'public'))); // init sequalize +const databasePath = path.resolve(__dirname, 'database/database.sqlite'); const sequelize = new Sequelize({ dialect: 'sqlite', - storage: 'database/database.sqlite', + storage: databasePath, logging: false, }); diff --git a/docker-compose.yaml b/docker-compose.yaml index 1e2eb78..b6e2ac5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,7 +9,7 @@ services: - SECRET_KEY=your_secret_key_here - IS_DEMO=false # set to true to seed the database volumes: - - db-data:/app/database + - db-data:/app/backend/database volumes: db-data: diff --git a/e2e/index.spec.ts b/e2e/index.spec.ts deleted file mode 100644 index 7942bb7..0000000 --- a/e2e/index.spec.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { test, expect } from '@playwright/test'; - -test('has title', async ({ page }) => { - await page.goto('http://localhost:8000/'); - await expect(page).toHaveTitle('Open Source Test Case Management System | UnitTCMS'); -}); diff --git a/e2e/not-demo-mode.spec.ts b/e2e/not-demo-mode.spec.ts new file mode 100644 index 0000000..9c030db --- /dev/null +++ b/e2e/not-demo-mode.spec.ts @@ -0,0 +1,12 @@ +import { test, expect } from '@playwright/test'; + +test('If not demo mode, the landing page will not be displayed and will be redirected to the projects page.', async ({ + page, +}) => { + const screenshotDir = 'playwright-screenshots/not-demo-redirect'; + + await page.goto('http://localhost:8000/'); + await expect(page).toHaveURL(/\/projects/); + + await page.screenshot({ path: `${screenshotDir}/landing-page-redirect.png`, fullPage: true }); +});