Skip to content

Commit

Permalink
ui: add react ui
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinjamul committed Feb 16, 2024
1 parent a677816 commit 718bf5e
Show file tree
Hide file tree
Showing 16 changed files with 2,695 additions and 7 deletions.
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(cors()); // cors for cross origin access

// Import routers
Expand Down
6 changes: 3 additions & 3 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const authRouter = require("./auth");
const apiRouter = require("./api");

/* All routes */

// Frontend Route
router.use("/", viewRouter);
// Authentication route
router.use("/auth", authRouter);

router.use("/api", apiRouter);

// Frontend Route
router.use("/", viewRouter);

module.exports = router;
24 changes: 21 additions & 3 deletions routes/views.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
var express = require('express');
var express = require("express");
var router = express.Router();

var path = require("path");

// GET assets
router.use(
"/assets",
express.static(path.join(__dirname, "../ui/dist/assets"))
);
router.use(
"/vite.svg",
express.static(path.join(__dirname, "../ui/public/vite.svg"))
);

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
// all unmatched requests to this path, with no file extension, redirect to the dash page
router.use(["/", "/*"], function (req, res, next) {
// uri has a forward slash followed any number of any characters except full stops (up until the end of the string)
if (/\/[^.]*$/.test(req.url)) {
res.status(200).sendFile(path.join(__dirname, "../ui/dist/index.html"));
} else {
next();
}
});

module.exports = router;
21 changes: 21 additions & 0 deletions ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Pocket Memory Frontend
13 changes: 13 additions & 0 deletions ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "pocket-memory",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"vite": "^5.1.0"
}
}
Loading

0 comments on commit 718bf5e

Please sign in to comment.