forked from srgooglo/monstercanker
This commit is contained in:
parent
27792df4ca
commit
5761947915
|
@ -0,0 +1,41 @@
|
|||
# Secrets
|
||||
/**/**/.env
|
||||
/**/**/origin.server
|
||||
/**/**/server.manifest
|
||||
/**/**/server.registry
|
||||
/**/**/*.secret.*
|
||||
|
||||
/**/**/_shared
|
||||
|
||||
# Trash
|
||||
/**/**/*.log
|
||||
/**/**/dumps.log
|
||||
/**/**/.crash.log
|
||||
/**/**/.tmp
|
||||
/**/**/.cache
|
||||
/**/**/cache
|
||||
/**/**/out
|
||||
/**/**/.out
|
||||
/**/**/dist
|
||||
/**/**/node_modules
|
||||
/**/**/corenode_modules
|
||||
/**/**/.DS_Store
|
||||
/**/**/package-lock.json
|
||||
/**/**/yarn.lock
|
||||
/**/**/.evite
|
||||
/**/**/build
|
||||
/**/**/uploads
|
||||
/**/**/d_data
|
||||
/**/**/*.tar
|
||||
/**/**/*.7z
|
||||
/**/**/*.zip
|
||||
/**/**/*.env
|
||||
|
||||
# Logs
|
||||
/**/**/npm-debug.log*
|
||||
/**/**/yarn-error.log
|
||||
/**/**/dumps.log
|
||||
/**/**/corenode.log
|
||||
|
||||
# Temporal configurations
|
||||
/**/**/.aliaser
|
|
@ -0,0 +1,40 @@
|
|||
require('dotenv').config()
|
||||
|
||||
const express = require("express")
|
||||
const cors = require("cors")
|
||||
const mlib = require("../../node_lib")
|
||||
|
||||
let app = null
|
||||
|
||||
const { LISTENING_PORT } = process.env
|
||||
const PORT = LISTENING_PORT || 3000
|
||||
|
||||
async function main() {
|
||||
app = express()
|
||||
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
|
||||
app.get("/api", async (req, res) => {
|
||||
let { random } = req.query
|
||||
|
||||
// try to parse random, can be a number or a boolean
|
||||
if (random) {
|
||||
if (random === "true") {
|
||||
random = true
|
||||
} else if (Number(random)) {
|
||||
random = Number(random)
|
||||
}
|
||||
}
|
||||
|
||||
const phrases = await mlib({ random })
|
||||
|
||||
res.json(phrases)
|
||||
})
|
||||
|
||||
app.listen(PORT)
|
||||
|
||||
console.log(`Listening on port ${PORT}`)
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "node_api",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.1",
|
||||
"express": "^4.18.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
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-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
}
|
|
@ -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?
|
|
@ -0,0 +1,8 @@
|
|||
# React + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
@ -0,0 +1,16 @@
|
|||
<!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>Monstercanker</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "web",
|
||||
"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": {
|
||||
"axios": "^1.6.7",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.43",
|
||||
"@types/react-dom": "^18.2.17",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"eslint": "^8.55.0",
|
||||
"eslint-plugin-react": "^7.33.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.5",
|
||||
"vite": "^5.0.8"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme : light dark;
|
||||
color : rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis : none;
|
||||
text-rendering : optimizeLegibility;
|
||||
-webkit-font-smoothing : antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight : 500;
|
||||
color : #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
display : flex;
|
||||
flex-direction: column;
|
||||
|
||||
margin : 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size : 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius : 8px;
|
||||
border : 1px solid transparent;
|
||||
padding : 0.6em 1.2em;
|
||||
font-size : 1em;
|
||||
font-weight : 500;
|
||||
font-family : inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor : pointer;
|
||||
transition : border-color 0.25s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
.app {
|
||||
display : flex;
|
||||
flex-direction: column;
|
||||
|
||||
align-items : center;
|
||||
justify-content: center;
|
||||
|
||||
width : 100%;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
footer {
|
||||
position: fixed;
|
||||
|
||||
bottom: 10vh;
|
||||
left : 0;
|
||||
|
||||
width : 100%;
|
||||
height: fit-content;
|
||||
|
||||
display: flex;
|
||||
|
||||
align-items : center;
|
||||
justify-content: center;
|
||||
|
||||
gap: 20px;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
import React from "react"
|
||||
import ReactDOM from "react-dom/client"
|
||||
|
||||
import axios from "axios"
|
||||
|
||||
import "./index.css"
|
||||
|
||||
const API_ENDPOINT = import.meta.env.PROD ? "/api" : `http://${window.location.hostname}:3000/api`
|
||||
|
||||
const App = () => {
|
||||
const [loading, setLoading] = React.useState(true)
|
||||
const [randomWord, setRandomWord] = React.useState(null)
|
||||
|
||||
async function loadRandom({
|
||||
random = true,
|
||||
} = {}) {
|
||||
setLoading(true)
|
||||
|
||||
let { data } = await axios({
|
||||
url: API_ENDPOINT,
|
||||
method: "GET",
|
||||
params: {
|
||||
random,
|
||||
},
|
||||
})
|
||||
|
||||
setLoading(false)
|
||||
|
||||
setRandomWord(data)
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
loadRandom()
|
||||
}, [])
|
||||
|
||||
return <div className="app">
|
||||
{
|
||||
loading ? <p>Loading...</p> : <h1>{randomWord}</h1>
|
||||
}
|
||||
|
||||
<footer>
|
||||
<a href="https://git.ragestudio.net/srgooglo/monstercanker">GitHub</a>
|
||||
<a href={API_ENDPOINT}>API</a>
|
||||
</footer>
|
||||
</div>
|
||||
}
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
|
@ -0,0 +1,29 @@
|
|||
const raw_text = "https://git.ragestudio.net/srgooglo/monstercanker/raw/branch/main/main.txt"
|
||||
|
||||
function randomSelect(array) {
|
||||
return array[Math.floor(Math.random() * array.length)]
|
||||
}
|
||||
|
||||
module.exports = async ({ random } = {}) => {
|
||||
const response = await fetch(raw_text)
|
||||
|
||||
let phrases = await response.text()
|
||||
|
||||
phrases = phrases.split("\n")
|
||||
|
||||
if (random) {
|
||||
if (typeof random === "number") {
|
||||
const randomSelections = []
|
||||
|
||||
for await (const _ of Array(random)) {
|
||||
randomSelections.push(randomSelect(phrases))
|
||||
}
|
||||
|
||||
phrases = randomSelections
|
||||
} else {
|
||||
phrases = randomSelect(phrases)
|
||||
}
|
||||
}
|
||||
|
||||
return phrases
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
const index = require(".")
|
||||
|
||||
async function main() {
|
||||
console.log(`Output entire list...`)
|
||||
|
||||
console.log(await index())
|
||||
|
||||
console.log(`Output 1 random phrase...`)
|
||||
|
||||
console.log(await index({ random: true }))
|
||||
|
||||
console.log(`Output 3 random phrase...`)
|
||||
|
||||
console.log(await index({ random: 3 }))
|
||||
}
|
||||
|
||||
main()
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue