Skip to content

Commit

Permalink
Few adjustments to allow to use the server properly fromn the fronten…
Browse files Browse the repository at this point in the history
…d app
  • Loading branch information
ebrehault committed Dec 11, 2023
1 parent 2e5ccc1 commit 4a2c1a3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 13 deletions.
31 changes: 31 additions & 0 deletions electron-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"license": "MIT",
"dependencies": {
"compression": "^1.7.4",
"cors": "^2.8.5",
"electron-squirrel-startup": "^1.0.0",
"express": "^4.18.2",
"rxjs": "^7.8.1",
Expand All @@ -41,6 +42,7 @@
"@electron-forge/plugin-auto-unpack-natives": "^6.4.2",
"@electron-forge/publisher-github": "^6.4.2",
"@types/compression": "^1.7.5",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.12.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import { Blob as FSBlob } from 'buffer';
import * as fs from 'fs';
import path from 'path';
import { Observable, forkJoin, map, of, switchMap } from 'rxjs';
import {
ConnectorParameters,
FileStatus,
IConnector,
Link,
SearchResults,
SyncItem,
} from 'src/logic/connector/domain/connector';
import { ConnectorParameters, FileStatus, IConnector, Link, SearchResults, SyncItem } from '../../domain/connector';
import { SourceConnectorDefinition } from '../factory';

const FILES_TO_IGNORE = ['.DS_Store', 'Thumbs.db'];
Expand Down
2 changes: 1 addition & 1 deletion electron-app/src/logic/errors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class CustomError extends Error {
constructor(
public readonly message: string,
public readonly statusCode: number = 400,
public readonly statusCode: number = 500,
) {
super(message);
}
Expand Down
2 changes: 1 addition & 1 deletion electron-app/src/logic/sync/domain/sync.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getConnector } from '../../connector/infrastructure/factory';

export type Connector = {
name: 'gdrive' | 'folder';
logo: string;
// logo: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
parameters: { [key: string]: any };
};
Expand Down
4 changes: 2 additions & 2 deletions electron-app/src/logic/sync/presentation/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class SyncFileSystemRoutes {

router.post('/', async (req, res) => {
const [error, createSyncDto] = CreateSyncDto.create(req.body);
if (error) return res.status(400).json({ error });
if (error) return res.status(500).json({ error });
try {
await new CreateSync(syncRepository).execute(createSyncDto!);
res.status(201).send({
Expand Down Expand Up @@ -86,7 +86,7 @@ export class SyncFileSystemRoutes {
router.patch('/:id', async (req, res) => {
const { id } = req.params;
const [error, updateSyncDto] = UpdateSyncDto.create({ ...req.body, id });
if (error) return res.status(400).json({ error });
if (error) return res.status(500).json({ error });

try {
await new UpdateSync(syncRepository).execute(updateSyncDto!);
Expand Down
13 changes: 12 additions & 1 deletion electron-app/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import compression from 'compression';
import express, { Router } from 'express';
import cors from 'cors';
import http from 'http';
import { EVENTS, EventEmitter } from './events/events';

Expand Down Expand Up @@ -46,10 +47,20 @@ export class Server {
}

async start() {
//* CORS
this.app.use(
cors({
origin: '*',
}),
);
//* Middlewares
this.app.use(express.json()); // raw
this.app.use(express.urlencoded({ extended: true })); // x-www-form-urlencoded
this.app.use(compression());
this.app.use((req, res, next) => {
res.setHeader('Content-Type', 'application/json');
next();
});

//* Routes
this.app.use(this.routes);
Expand All @@ -59,7 +70,7 @@ export class Server {
});

this.app.get('/status', async (_req, res) => {
res.status(200).send('Server is running');
res.status(200).send(JSON.stringify({ running: true }));
});

this.app.post('/stop', async (_req, res) => {
Expand Down

0 comments on commit 4a2c1a3

Please sign in to comment.