Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 31 additions & 30 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import { defineConfig, globalIgnores } from 'eslint/config'
import globals from "globals";
import pluginJs from "@eslint/js";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import pluginReactHooks from "eslint-plugin-react-hooks";
import pluginReactRefresh from "eslint-plugin-react-refresh";

export default defineConfig([
globalIgnores(['dist']),
export default [
{
files: ['**/*.{js,jsx}'],
extends: [
js.configs.recommended,
reactHooks.configs['recommended-latest'],
reactRefresh.configs.vite,
],
ignores: ["dist"],
},
{
files: ["**/*.{js,jsx}"],
...pluginJs.configs.recommended,
...pluginReactConfig,
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
"react-hooks": pluginReactHooks,
"react-refresh": pluginReactRefresh,
},
rules: {
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
'no-undef': 'error',

'react/jsx-no-undef': 'error',
'react/jsx-no-duplicate-props': 'error',
'react/no-direct-mutation-state': 'error',

'react-hooks/rules-of-hooks': 'error',

'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
"no-unused-vars": ["error", { "varsIgnorePattern": "^[A-Z_]" }],
"no-undef": "error",
"react/jsx-no-undef": "error",
"react/jsx-no-duplicate-props": "error",
"react/no-direct-mutation-state": "error",
"react-hooks/rules-of-hooks": "error",
"react-refresh/only-export-components": [
"warn",
{ "allowConstantExport": true },
],
},
},
])
];
41 changes: 6 additions & 35 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
[build]
# Directory to change to before starting a build
base = "."
# Directory that contains the deploy-ready HTML files and assets
publish = "dist"
# Default build command
command = "pnpm run build"

[build.environment]
# Use Node.js version 18 or higher
NODE_VERSION = "18"
# Use pnpm as package manager
NPM_FLAGS = "--version" # This tells Netlify to use pnpm

# SPA redirect rules - this is crucial for React Router
[[redirects]]
from = "/*"
to = "/index.html"
from = "/api/*"
to = "/.netlify/functions/api/:splat"
status = 200

# Security headers
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-XSS-Protection = "1; mode=block"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "strict-origin-when-cross-origin"

# Cache static assets
[[headers]]
for = "/static/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[build]
functions = "netlify/functions"

[[headers]]
for = "/assets/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[plugins]]
package = "@netlify/plugin-functions-install-core"
62 changes: 62 additions & 0 deletions netlify/functions/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const express = require('express');
const mongoose = require('mongoose');
const serverless = require('serverless-http');
const cors = require('cors');
require('dotenv').config();

const app = express();
const router = express.Router();

app.use(cors());
app.use(express.json());

// MongoDB Connection
const uri = process.env.MONGODB_URI;

mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('MongoDB database connection established successfully'))
.catch(err => console.error('MongoDB connection error:', err));

// FileHistory Schema and Model
const fileHistorySchema = new mongoose.Schema({
fileName: { type: String, required: true, trim: true },
uploadDate: { type: Date, required: true },
size: { type: String, required: true },
user: { type: String, required: true },
}, { timestamps: true });

const FileHistory = mongoose.model('FileHistory', fileHistorySchema);

// Routes
router.get('/history', async (req, res) => {
try {
const history = await FileHistory.find({ user: req.query.user });
res.json(history);
} catch (err) {
res.status(400).json('Error: ' + err);
}
});

router.post('/history/add', async (req, res) => {
try {
const { fileName, uploadDate, size, user } = req.body;
const newFileHistory = new FileHistory({ fileName, uploadDate, size, user });
await newFileHistory.save();
res.json('File history added!');
} catch (err) {
res.status(400).json('Error: ' + err);
}
});

router.delete('/history/:id', async (req, res) => {
try {
await FileHistory.findByIdAndDelete(req.params.id);
res.json('File history deleted.');
} catch (err) {
res.status(400).json('Error: ' + err);
}
});

app.use('/.netlify/functions/api', router); // Mount the router at the base path of the Netlify function

module.exports.handler = serverless(app);
9 changes: 9 additions & 0 deletions netlify/functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^17.0.1",
"express": "^5.1.0",
"mongoose": "^8.16.1",
"serverless-http": "^3.2.0"
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
"@tailwindcss/vite": "^4.1.11",
"auth0-spa-js": "^1.6.5",
"axios": "^1.10.0",
"bson": "^6.10.4",
"chart.js": "^4.5.0",
"dotenv": "^17.0.0",
"cors": "^2.8.5",
"dotenv": "^17.0.1",
"express": "^5.1.0",
"express-jwt": "^8.5.1",
"file-saver": "^2.0.5",
Expand All @@ -32,6 +34,7 @@
"react-dom": "^19.1.0",
"react-router-dom": "^7.6.3",
"recharts": "^3.0.2",
"serverless-http": "^3.2.0",
"xlsx": "^0.18.5"
},
"devDependencies": {
Expand All @@ -41,6 +44,7 @@
"@vitejs/plugin-react": "^4.5.2",
"autoprefixer": "^10.4.21",
"eslint": "^9.29.0",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.20",
"globals": "^16.2.0",
Expand Down
Loading