Compare commits

..

4 Commits

16 changed files with 1283 additions and 10 deletions

16
client/cypress.config.ts Normal file
View File

@ -0,0 +1,16 @@
import { defineConfig } from "cypress";
export default defineConfig({
component: {
devServer: {
framework: "react",
bundler: "vite",
},
},
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});

View File

@ -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"
}

View File

@ -0,0 +1,44 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts 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) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>;
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>;
// dismiss(
// subject: string,
// options?: Partial<TypeOptions>
// ): Chainable<Element>;
// visit(
// originalFn: CommandOriginalFn,
// url: string,
// options: Partial<VisitOptions>
// ): Chainable<Element>;
// }
// }
// }

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>

View File

@ -0,0 +1,39 @@
// ***********************************************************
// This example support/component.ts 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')
import { mount } from 'cypress/react18'
// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}
Cypress.Commands.add('mount', mount)
// Example use:
// cy.mount(<MyComponent />)

View File

@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts 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')

View File

@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"isolatedModules": false
}
}

View File

@ -6,7 +6,8 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build --outDir ../dist",
"preview": "vite preview"
"preview": "vite preview",
"cypress": "cypress"
},
"dependencies": {
"@headlessui/react": "^1.7.2",
@ -23,10 +24,12 @@
"zod": "^3.19.1"
},
"devDependencies": {
"@testing-library/cypress": "^8.0.3",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.1.0",
"autoprefixer": "^10.4.12",
"cypress": "^10.9.0",
"postcss": "^8.4.16",
"prettier": "^2.7.1",
"tailwindcss": "^3.1.8",

1091
client/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -2,10 +2,14 @@ import { Routes, Route } from "react-router-dom";
import BrowseLayout from "./components/BrowseLayout";
import CategoryPage from "./pages/CategoryPage";
import ChannelPage from "./pages/ChannelPage";
import LoginPage from "./pages/LoginPage";
import SignupPage from "./pages/SignupPage";
function App() {
return (
<Routes>
<Route path="/login" element={<LoginPage />} />
<Route path="/signup" element={<SignupPage />} />
<Route element={<BrowseLayout />}>
<Route path="/:channel" element={<ChannelPage />} />
<Route path="/category/:category" element={<CategoryPage />} />

View File

@ -0,0 +1,12 @@
import { FC } from "react";
import LoginModal from "../components/LoginModal";
const LoginPage: FC = () => {
return (
<div className="bg-neutral-900 w-screen h-screen">
<LoginModal isOpen={true} defaultPage={0} onClose={() => {}} />
</div>
);
};
export default LoginPage;

View File

@ -0,0 +1,12 @@
import { FC } from "react";
import LoginModal from "../components/LoginModal";
const SignupPage: FC = () => {
return (
<div className="bg-neutral-900 w-screen h-screen">
<LoginModal isOpen={true} defaultPage={1} onClose={() => {}} />
</div>
);
};
export default SignupPage;

View File

@ -14,8 +14,9 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"types": ["@testing-library/crypress", "cypress"]
},
"include": ["src"],
"include": ["src", "cypress"],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

@ -10,10 +10,10 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/csrf"
"github.com/gofiber/fiber/v2/middleware/logger"
)
/*Init : set the port,cors,api and then serve the api*/
func Init() {
app := fiber.New(fiber.Config{
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
@ -33,6 +33,10 @@ func Init() {
AllowCredentials: true,
}))
app.Use(logger.New())
app.Use(csrf.New(csrf.Config{
CookieHTTPOnly: true,
CookieSameSite: "strict",
}))
api := app.Group("/api")
v1 := api.Group("/v1")
@ -46,7 +50,7 @@ func Init() {
return c.SendString("This is a protected route!")
})
// Serve SPA
// Serve React frontend
app.Static("/", "./dist")
app.Get("/*", func(ctx *fiber.Ctx) error {
return ctx.SendFile("./dist/index.html")

View File

@ -42,5 +42,12 @@ func Login(ctx *fiber.Ctx) error {
return err
}
ctx.Cookie(&fiber.Cookie{
Name: "accessToken",
Value: token,
HTTPOnly: true,
SameSite: "Strict",
})
return ctx.JSON(LoginResponse{Token: token})
}

View File

@ -41,5 +41,12 @@ func Register(ctx *fiber.Ctx) error {
return err
}
ctx.Cookie(&fiber.Cookie{
Name: "accessToken",
Value: token,
HTTPOnly: true,
SameSite: "Strict",
})
return ctx.JSON(LoginResponse{Token: token})
}