Update to upstream
This commit is contained in:
commit
16ba7d2e8c
15 changed files with 3855 additions and 0 deletions
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
|
@ -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?
|
17
Dockerfile_backend
Normal file
17
Dockerfile_backend
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
|
||||||
|
|
||||||
|
WORKDIR /home/node/app
|
||||||
|
|
||||||
|
COPY --chown=node:node . .
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
EXPOSE 85
|
||||||
|
|
||||||
|
CMD ["npm", "run", "backend"]
|
21
Dockerfile_frontend
Normal file
21
Dockerfile_frontend
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
FROM node:20-alpine AS vite_builder
|
||||||
|
|
||||||
|
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
|
||||||
|
|
||||||
|
WORKDIR /home/node/app
|
||||||
|
|
||||||
|
COPY --chown=node:node . .
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY --from=vite_builder /home/node/app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
13
README.md
Normal file
13
README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Sproof Challenge
|
||||||
|
## (Mirror adjusted for local deployments)
|
||||||
|
|
||||||
|
# Setup:
|
||||||
|
|
||||||
|
- docker compose up -d
|
||||||
|
- visit http://localhost:8090
|
||||||
|
|
||||||
|
(For actual deployment, nginx in docker is used as reverse proxy + cloudflare as cache/proxy)
|
||||||
|
|
||||||
|
### This is a "semi" mirror that does not have the original commit history due to privacy reasons.
|
||||||
|
Made from the template: npm create vite@latest sproof_challenge -- --template react
|
||||||
|
[Link](https://vitejs.dev/guide/)
|
3
Setup.bat
Normal file
3
Setup.bat
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
title "Setting up..."
|
||||||
|
docker compose up -d
|
||||||
|
start "" http://localhost:8090/
|
3
Setup.sh
Normal file
3
Setup.sh
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
sudo docker compose up -d
|
||||||
|
xdg-open http://localhost:8090/
|
||||||
|
# requires compliant freedesktop implementation!
|
23
backend/server.js
Normal file
23
backend/server.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// I prefer backend over frontend...
|
||||||
|
import express from 'express';
|
||||||
|
|
||||||
|
|
||||||
|
const APP = express();
|
||||||
|
const PORT = process.env.PORT || 85;
|
||||||
|
|
||||||
|
APP.use(express.json()); // ability to parse json
|
||||||
|
|
||||||
|
APP.post('/api/v1/sign', async (req, res) => {
|
||||||
|
const {password, fullName} = req.body;
|
||||||
|
console.log('POST request body:', password);
|
||||||
|
if (password === "1337" && fullName) {
|
||||||
|
res.status(200).send(JSON.stringify("Success"));
|
||||||
|
} else {
|
||||||
|
res.status(401).send(JSON.stringify("Not authorized"));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
APP.listen(PORT, () => {
|
||||||
|
console.log('Server is running on port 85');
|
||||||
|
});
|
30
docker-compose.yaml
Normal file
30
docker-compose.yaml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
name: sproof_challenge
|
||||||
|
services:
|
||||||
|
sproof_frontend:
|
||||||
|
restart: always
|
||||||
|
hostname: sproof_frontend
|
||||||
|
container_name: sproof_frontend
|
||||||
|
ports:
|
||||||
|
- '8090:80'
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile_frontend
|
||||||
|
deploy:
|
||||||
|
restart_policy:
|
||||||
|
condition: any
|
||||||
|
delay: 15s
|
||||||
|
window: 120s
|
||||||
|
sproof_backend:
|
||||||
|
restart: always
|
||||||
|
hostname: sproof_backend
|
||||||
|
container_name: sproof_backend
|
||||||
|
ports:
|
||||||
|
- '8095:85'
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile_backend
|
||||||
|
deploy:
|
||||||
|
restart_policy:
|
||||||
|
condition: any
|
||||||
|
delay: 15s
|
||||||
|
window: 120s
|
13
index.html
Normal file
13
index.html
Normal file
|
@ -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>Sproof Challenge</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
3578
package-lock.json
generated
Normal file
3578
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
21
package.json
Normal file
21
package.json
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"name": "sproof_challenge",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite --host",
|
||||||
|
"build": "vite build",
|
||||||
|
"backend": "node backend/server.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@mui/material": "^5.16.7",
|
||||||
|
"express": "^4.19.2",
|
||||||
|
"react": "^17.0.0 || ^18.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "^18.3.3",
|
||||||
|
"@vitejs/plugin-react": "^4.3.1",
|
||||||
|
"vite": "^5.4.0"
|
||||||
|
}
|
||||||
|
}
|
1
public/vite.svg
Normal file
1
public/vite.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
91
src/App.jsx
Normal file
91
src/App.jsx
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
import React, {useState} from 'react'
|
||||||
|
import {TextField, Avatar, Button} from '@mui/material'
|
||||||
|
|
||||||
|
|
||||||
|
const PDFEmbed = ({pdfUrl}) => {
|
||||||
|
return (<embed
|
||||||
|
src={pdfUrl}
|
||||||
|
type="application/pdf"
|
||||||
|
style={{width: '100%', height: '100%'}}
|
||||||
|
title="PDF Viewer"
|
||||||
|
/>)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function App() {
|
||||||
|
const [inputValue, setInputValue] = useState('')
|
||||||
|
const [pin, setPin] = useState('')
|
||||||
|
|
||||||
|
const handleInputChange = (event) => {
|
||||||
|
setInputValue(event.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePinChange = (event) => {
|
||||||
|
setPin(event.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!inputValue || !pin) {
|
||||||
|
alert('Both fields are required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
fullName: inputValue, password: pin,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8095/api/v1/sign', {
|
||||||
|
method: 'POST', headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}, body: JSON.stringify(data),
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const result = await response.json()
|
||||||
|
alert("Successfully signed the Document!")
|
||||||
|
} else {
|
||||||
|
alert("An error occurred (Check your submitted Data!)")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const pdfUrl = 'https://dagrs.berkeley.edu/sites/default/files/2020-01/sample.pdf'
|
||||||
|
|
||||||
|
return (<div style={{display: 'flex', flexDirection: 'column', height: '98vh'}}>
|
||||||
|
<div style={{padding: '1rem', display: 'flex', alignItems: 'center', justifyContent: 'center'}}>
|
||||||
|
<Avatar>{inputValue.charAt(0).toUpperCase()}</Avatar>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{padding: '1rem', display: 'flex', alignItems: 'center', justifyContent: 'center'}}>
|
||||||
|
<TextField
|
||||||
|
required
|
||||||
|
id="fullname"
|
||||||
|
label="Full Legal Name"
|
||||||
|
name="fullname"
|
||||||
|
autoComplete="name"
|
||||||
|
value={inputValue}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
style={{marginRight: '1rem', flex: 1}}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
required
|
||||||
|
id="Pin"
|
||||||
|
label="Password"
|
||||||
|
name="password"
|
||||||
|
autoComplete="one-time-code"
|
||||||
|
value={pin}
|
||||||
|
onChange={handlePinChange}
|
||||||
|
style={{marginRight: '1rem', flex: 1, maxWidth: '20%'}}
|
||||||
|
/>
|
||||||
|
<Button variant="contained" onClick={handleSubmit}>Sign</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{flex: 1, overflow: 'hidden'}}>
|
||||||
|
<PDFEmbed pdfUrl={pdfUrl}/>
|
||||||
|
</div>
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App
|
10
src/main.tsx
Normal file
10
src/main.tsx
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import {StrictMode} from 'react'
|
||||||
|
import {createRoot} from 'react-dom/client'
|
||||||
|
// @ts-ignore
|
||||||
|
import App from './App.jsx'
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')).render(
|
||||||
|
<StrictMode>
|
||||||
|
<App/>
|
||||||
|
</StrictMode>,
|
||||||
|
)
|
7
vite.config.js
Normal file
7
vite.config.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react'
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
})
|
Reference in a new issue