-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch badges directly from Shields.io, Add more customizations, Add e…
…asy to use badge generator
- Loading branch information
1 parent
84696d5
commit 04d5e79
Showing
53 changed files
with
11,228 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.x | ||
- run: yarn install --frozen-lockfile | ||
- run: yarn run build | ||
- name: Run git push | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "earphone-jack" | ||
git add --all | ||
git commit -m "Build output for commit $GITHUB_SHA" || true | ||
git push | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import express from 'express'; | ||
import got from 'got'; | ||
import http from 'http'; | ||
import https from 'https'; | ||
import NodeCache from 'node-cache'; | ||
|
||
const app = express(); | ||
const cache = new NodeCache(); | ||
|
||
interface Badge { | ||
key: string, | ||
value: string, | ||
color: string, | ||
style: string, | ||
logo: string, | ||
} | ||
|
||
async function createBadge(badge: Badge) { | ||
badge.value = badge.value.replace(/-/g, '--'); | ||
const url = new URL(`http://img.shields.io/badge/${badge.key}-${badge.value}-${badge.color}?style=${badge.style}&logo=${badge.logo}`); | ||
|
||
if (cache.has(url.toString())) { | ||
return cache.get(url.toString()); | ||
} | ||
|
||
const response = (await got(url)).body; | ||
cache.set(url.toString(), response); | ||
return response; | ||
} | ||
|
||
app.use(express.static(__dirname + '/frontend/build', {index: false})); | ||
app.get('/*', (req, res) => { | ||
|
||
if (!("app" in req.query)) { | ||
return res.status(200).sendFile(__dirname + '/frontend/build/index.html'); | ||
} | ||
|
||
const appName = req.query.app; | ||
const root = req.query.root ?? ''; | ||
const style = req.query.style ?? 'flat'; | ||
const badgeName = req.query.name ?? 'vercel' | ||
const logo = req.query.logo ?? 'vercel'; | ||
|
||
const url = appName + '.vercel.app/' + root; | ||
const handleRequest = async (statusCode: number = 404) => { | ||
const badge: Badge = { | ||
key: (badgeName as string).replace(/-/g, '--').replace(/_/g, '__'), | ||
value: 'deployed', | ||
color: 'brightgreen', | ||
style: style as string, | ||
logo: logo as string, | ||
}; | ||
|
||
if (statusCode <= 599 && statusCode >= 500) { | ||
// 500 - 599 -> Server Errors | ||
badge.value = 'failed'; | ||
badge.color = 'red'; | ||
} else if (statusCode <= 499 && statusCode >= 400) { | ||
// 400 - 499 -> Client Errors | ||
badge.value = 'not-found'; | ||
badge.color = 'lightgrey'; | ||
} else if (statusCode <= 399 && statusCode >= 300) { | ||
// 300 - 399 -> Redirects | ||
} | ||
|
||
// 200 - 299 -> Successful Responses | ||
// 100 - 199 -> Informational Responses | ||
|
||
res.setHeader('Content-type', 'image/svg+xml'); | ||
res.status(200).send(await createBadge(badge)); | ||
} | ||
|
||
try { | ||
https.get("https://" + url, async (response) => { | ||
var statusCode = response.statusCode; | ||
await handleRequest(statusCode); | ||
}).on('error', () => { | ||
// This could mean the HTTPS site is not available so we check for HTTP | ||
http.get("http://" + url, async (response) => { | ||
var statusCode = response.statusCode; | ||
await handleRequest(statusCode); | ||
}).on('error', () => { | ||
// Invalid Application Name | ||
handleRequest(404); | ||
}); | ||
}); | ||
} catch { | ||
// An error was encountered for some unknown reason | ||
res.status(500).send('Internal Server Error. Please open an issue at <a href="https://github.com/therealsujitk/vercel-badge/issues">vercel-badge/issues</a>.'); | ||
} | ||
}); | ||
|
||
export default app; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import app from '../app'; | ||
import http from 'http'; | ||
|
||
const httpServer = http.createServer(app); | ||
const port = process.env.PORT || 3000; | ||
|
||
/* | ||
Starting the listener | ||
*/ | ||
httpServer.listen(port, () => { | ||
console.log('listening on *:' + port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Getting Started with Create React App | ||
|
||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
|
||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
### `npm start` | ||
|
||
Runs the app in the development mode.\ | ||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
|
||
The page will reload if you make edits.\ | ||
You will also see any lint errors in the console. | ||
|
||
### `npm test` | ||
|
||
Launches the test runner in the interactive watch mode.\ | ||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | ||
|
||
### `npm run build` | ||
|
||
Builds the app for production to the `build` folder.\ | ||
It correctly bundles React in production mode and optimizes the build for the best performance. | ||
|
||
The build is minified and the filenames include the hashes.\ | ||
Your app is ready to be deployed! | ||
|
||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | ||
|
||
### `npm run eject` | ||
|
||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!** | ||
|
||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. | ||
|
||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. | ||
|
||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. | ||
|
||
## Learn More | ||
|
||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). | ||
|
||
To learn React, check out the [React documentation](https://reactjs.org/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "frontend", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@emotion/react": "^11.11.1", | ||
"@emotion/styled": "^11.11.0", | ||
"@mui/joy": "^5.0.0-beta.17", | ||
"@testing-library/jest-dom": "^5.17.0", | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/user-event": "^13.5.0", | ||
"@types/jest": "^27.5.2", | ||
"@types/node": "^16.18.68", | ||
"@types/react": "^18.2.42", | ||
"@types/react-dom": "^18.2.17", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-scripts": "5.0.1", | ||
"typescript": "^4.9.5", | ||
"web-vitals": "^2.1.4" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.