Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project page refactoring #214

Merged
merged 29 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ jobs:
APP=admin
START_COMMAND=start

- name: Build Server
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}/server:${{ github.event.inputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
COMMIT=${{ steps.vars.outputs.sha_short }}
APP=server
START_COMMAND=start

- name: Build Frontend
uses: docker/build-push-action@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ dist/

.vscode
.backups
.ethereal
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ARG COMMIT
ENV APP=${APP}
ENV START_COMMAND=${START_COMMAND}
ENV COMMIT=${COMMIT}
ENV VITE_COMMIT=${COMMIT}
ENV PORT=3000

COPY --from=builder /app .
Expand Down
10 changes: 3 additions & 7 deletions apps/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
"@adminjs/import-export": "^3.0.0",
"@adminjs/prisma": "^5.0.1",
"@adminjs/themes": "^1.0.1",
"@celluloid/passport": "*",
"@celluloid/prisma": "*",
"adminjs": "^7.2.2",
"bcryptjs": "^2.4.3",
"connect-redis": "^7.1.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-formidable": "^1.2.0",
"express-session": "^1.17.3",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"redis": "^4.6.10"
"express-session": "^1.17.3"
},
"devDependencies": {
"@celluloid/config": "*",
Expand All @@ -37,7 +33,7 @@
"@types/node": "^18.14.2",
"copyfiles": "^2.4.1",
"del-cli": "^5.0.0",
"dotenv-cli": "^7.2.1",
"dotenv-cli": "^7.3.0",
"np": "^7.7.0",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
Expand Down
8 changes: 3 additions & 5 deletions apps/admin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
import { createSession, passport } from '@celluloid/passport';
import { UserRole } from '@celluloid/prisma';
import cors from "cors";
import express, { NextFunction, Request, Response } from "express";
import path from "path";
import * as url from 'url'

import passport from "./passport"
import getAdminRouter from "./server.js";
import { createSession } from './session';


const PORT = process.env.PORT || 4000


const start = async () => {
const app = express();
app.enable('trust proxy');
app.use(cors({ credentials: true, origin: true }));
app.use(createSession());
app.use(passport.authenticate("session"));


// Define the CORS middleware function
const corsMiddleware = (req: Request, res: Response, next: NextFunction) => {
// Set the CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');

// Call the next middleware function in the chain
next();
};

// Add the CORS middleware function to the application
app.use(corsMiddleware);


const adminRouter = await getAdminRouter({
rootPath: "/admin"
});
Expand Down
11 changes: 4 additions & 7 deletions apps/admin/src/passport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import { prisma } from "@celluloid/prisma"
import { User } from '@celluloid/prisma';
import { prisma, User, UserRole } from "@celluloid/prisma"
import bcrypt from 'bcryptjs';
import passport from 'passport';
import {
Expand All @@ -21,7 +20,6 @@ passport.serializeUser((user: User, done) => {
passport.deserializeUser(async (id: string, done) => {
const user = await prisma.user.findUnique({ where: { id } })
if (user) {
console.log("here", user)
return done(null, user);
} else {
console.error(
Expand All @@ -40,7 +38,7 @@ passport.use(
if (!bcrypt.compareSync(password, user.password)) {
return done(new Error("InvalidUser"));
}
if (!user.confirmed && user.role !== "Student") {
if (!user.confirmed && user.role !== UserRole.Student) {
return done(new Error("UserNotConfirmed"));
}
return done(null, user);
Expand All @@ -55,8 +53,7 @@ const loginStrategy = new LocalStrategy(

const user = await prisma.user.findUnique({
where: {
//OR: [{ email: login }, { username: login, }]
email: login
OR: [{ email: login }, { username: login, }]
}
});

Expand All @@ -67,7 +64,7 @@ const loginStrategy = new LocalStrategy(
console.error(`Login failed for user ${user.username}: incorrect password`);
return Promise.resolve(done(new Error("InvalidUser")));
}
if (!user.confirmed && user.role !== "Student") {
if (!user.confirmed && user.role !== UserRole.Student) {
console.error(`Login failed: ${user.username} is not confirmed`);
return Promise.resolve(done(new Error("UserNotConfirmed")));
}
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const getAdminRouter = (options: Partial<AdminJSOptions> = {}) => {
name: 'Projects',
icon: 'Play',
},
listProperties: ['title', 'description', 'public', 'shared', 'publishedAt', 'user'],
listProperties: ['title', 'description', 'public', 'shared', 'publishedAt', 'user', 'duration', 'thumbnailURL', 'metadata'],
filterProperties: ['title', 'description', 'user'],
editProperties: ['title', 'description', 'public', 'shared'],
actions: {
Expand Down
26 changes: 16 additions & 10 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@
"name": "backend",
"private": true,
"version": "2.0.1",
"license": "MIT",
"homepage": "https://celluloid.huma-num.fr",
"repository": {
"type": "git",
"url": "https://github.com/celluloid-camp/celluloid.git",
"directory": "apps/frontend"
},
"bugs": {
"url": "https://github.com/udecode/plate/celluloid/issues"
},
"type": "module",
"scripts": {
"build": "tsup",
"dev": "dotenv -e ../../.env -- tsup --watch --silent --onSuccess 'node dist/index.js'",
"dev": "tsup --watch --silent --onSuccess 'node dist/index.js'",
"start": "node dist/index",
"test-start": "start-server-and-test 'node dist/index' 2021"
},
"dependencies": {
"@celluloid/passport": "*",
"@celluloid/prisma": "*",
"@celluloid/trpc": "*",
"@trpc/server": "^10.38.5",
"bcryptjs": "^2.4.3",
"@godaddy/terminus": "^4.12.1",
"@trpc/server": "^10.41.0",
"change-case": "^5.0.2",
"connect-redis": "^7.1.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-session": "^1.17.3",
"lodash": "^4.17.21",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"redis": "^4.6.10",
"swagger-ui-express": "^5.0.0",
"trpc-openapi": "^1.2.0",
"uuid": "^9.0.1",
"zod": "^3.22.2"
"zod": "^3.22.4"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/node": "^20.8.2",
"@types/swagger-ui-express": "^4.1.3",
"@types/uuid": "^9.0.4",
"dotenv-cli": "^7.3.0",
"start-server-and-test": "^2.0.0",
"start-server-and-test": "^2.0.1",
"tslib": "^2.6.2",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
Expand Down
25 changes: 17 additions & 8 deletions apps/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { createSession, passport } from '@celluloid/passport';
import { prisma } from '@celluloid/prisma';
import { appRouter, createRPCContext } from '@celluloid/trpc';
import { createTerminus } from '@godaddy/terminus';
import * as trpcExpress from '@trpc/server/adapters/express';
import cookieParser from 'cookie-parser';
import cors from 'cors';
Expand All @@ -7,12 +10,9 @@ import swaggerUi from 'swagger-ui-express';
import { createOpenApiExpressMiddleware } from 'trpc-openapi';

import { openApiDocument } from './openapi';
import passport from "./passport";
import { createSession } from './session';

const trpcApiEndpoint = '/trpc'


async function main() {
// express implementation
const app = express();
Expand Down Expand Up @@ -47,20 +47,29 @@ async function main() {
createContext: createRPCContext,
}),
);

// Handle incoming OpenAPI requests
app.use('/api', createOpenApiExpressMiddleware({ router: appRouter, createContext: createRPCContext }));


// Serve Swagger UI with our OpenAPI schema
app.use('/', swaggerUi.serve);
app.get('/', swaggerUi.setup(openApiDocument));



app.listen(process.env.PORT || 2021, () => {
const server = app.listen(process.env.PORT || 2021, () => {
console.log('listening on port 2021');
});

async function onSignal() {
console.log('server is starting cleanup')
await prisma.$disconnect()
return;
}

createTerminus(server, {
// signal: 'SIGINT',
// healthChecks: { '/healthcheck': onHealthCheck },
signals: ['SIGTERM', 'SIGINT'],
onSignal
})
}

void main();
Expand Down
78 changes: 0 additions & 78 deletions apps/backend/src/passport.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
Loading
Loading