Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Commit ccf4fe0

Browse files
committed
Major Revamps to file layout and README
1 parent 948d387 commit ccf4fe0

20 files changed

+142
-140
lines changed

.github/workflows/bumpsh.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
doc: 'e1e8a461-3b29-4d71-a8fc-010429c9761e'
2828
token: ${{secrets.BUMP_TOKEN}}
29-
file: doc/api-documentation.yml
29+
file: documentation/api-documentation.yml
3030
api-diff:
3131
if: ${{ github.event_name == 'pull_request' }}
3232
name: Check API diff on Bump
@@ -39,7 +39,7 @@ jobs:
3939
with:
4040
doc: 'e1e8a461-3b29-4d71-a8fc-010429c9761e'
4141
token: ${{secrets.BUMP_TOKEN}}
42-
file: doc/api-documentation.yml
42+
file: documentation/api-documentation.yml
4343
command: diff
4444
env:
4545
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/codeql.yml

-48
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,33 @@
1-
# For most projects, this workflow file will not need changing; you simply need
2-
# to commit it to your repository.
3-
#
4-
# You may wish to alter this file to override the set of languages analyzed,
5-
# or to provide custom queries or build logic.
6-
#
7-
# ******** NOTE ********
8-
# We have attempted to detect the languages in your repository. Please check
9-
# the `language` matrix defined below to confirm you have the correct set of
10-
# supported CodeQL languages.
11-
#
121
name: "CodeQL"
13-
142
on:
153
push:
164
branches: [ "main" ]
175
pull_request:
18-
# The branches below must be a subset of the branches above
196
branches: [ "main" ]
207
schedule:
218
- cron: '16 20 * * 4'
22-
239
jobs:
2410
analyze:
2511
name: Analyze
26-
# Runner size impacts CodeQL analysis time. To learn more, please see:
27-
# - https://gh.io/recommended-hardware-resources-for-running-codeql
28-
# - https://gh.io/supported-runners-and-hardware-resources
29-
# - https://gh.io/using-larger-runners
30-
# Consider using larger runners for possible analysis time improvements.
3112
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
3213
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
3314
permissions:
3415
actions: read
3516
contents: read
3617
security-events: write
37-
3818
strategy:
3919
fail-fast: false
4020
matrix:
4121
language: [ 'javascript' ]
42-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
43-
# Use only 'java' to analyze code written in Java, Kotlin or both
44-
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
45-
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
46-
4722
steps:
4823
- name: Checkout repository
4924
uses: actions/checkout@v3
50-
51-
# Initializes the CodeQL tools for scanning.
5225
- name: Initialize CodeQL
5326
uses: github/codeql-action/init@v2
5427
with:
5528
languages: ${{ matrix.language }}
56-
# If you wish to specify custom queries, you can do so here or in a config file.
57-
# By default, queries listed here will override any specified in a config file.
58-
# Prefix the list here with "+" to use these queries and those in the config file.
59-
60-
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
61-
# queries: security-extended,security-and-quality
62-
63-
64-
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
65-
# If this step fails, then you should remove it and run the build manually (see below)
6629
- name: Autobuild
6730
uses: github/codeql-action/autobuild@v2
68-
69-
# ℹ️ Command-line programs to run using the OS shell.
70-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
71-
72-
# If the Autobuild fails above, remove it and uncomment the following three lines.
73-
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
74-
75-
# - run: |
76-
# echo "Run, Build Application using script"
77-
# ./location_of_script_within_repo/buildscript.sh
78-
7931
- name: Perform CodeQL Analysis
8032
uses: github/codeql-action/analyze@v2
8133
with:

@types/index.d.ts

-3
This file was deleted.

README.md

+49
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,52 @@
33
This is the codebase for the official FemDevs homepage. It is built in Node.js using the Express framework.
44
Frontend code is writen in Pug.js and TailwindCSS.
55
API uses many free APIs provided by [Free APIs](https://free-apis.github.io/).
6+
7+
## How To Run
8+
First, you need to install [Node.js](https://nodejs.org/) and [npm](https://npmjs.com). Then, you can run the following commands to start the server:
9+
```bash
10+
npm i
11+
npm run build
12+
node .
13+
```
14+
15+
The Webpage will be available at `http://localhost:3000`. (Note; CDNs, assets, and APIs are automatically setup to pull from the official server (`SUBDOMAIN.thefemdevs.com`), and therefore will not work regualarly on localhost. You will need to make additional modifications to the code to be able to access said resources locally.)
16+
17+
## List of Tools
18+
- [Node.js](https://nodejs.org/) => JavaScript runtime
19+
- [Express](https://expressjs.com/) => Web framework for Node.js
20+
- [Pug.js](https://pugjs.org/) => Template engine for Node.js
21+
- [TailwindCSS](https://tailwindcss.com/) => Utility-first CSS framework
22+
- [PostCSS](https://postcss.org/) => A tool for transforming CSS with JavaScript
23+
- [Autoprefixer](https://npmjs.com/package/autoprefixer) => A plugin to parse CSS and add vendor prefixes to CSS rules
24+
- [Chalk](https://npmjs.com/package/chalk) => Terminal string styling done right
25+
- [Dotenv](https://npmjs.com/package/dotenv) => A zero-dependency module that loads environment variables from a .env file into process.env
26+
- [Express-Session](https://npmjs.com/package/express-session) => Create a session middleware
27+
- [Firebase](https://firebase.google.com/) => A platform developed by Google for creating mobile and web applications
28+
- [IP Info](https://ipinfo.io/) => A free IP geolocation API
29+
- [Axios](https://npmjs.com/package/axios) => Promise based HTTP client for the browser and node.js
30+
- [Postgres](https://www.postgresql.org/) => A powerful, open source object-relational database system
31+
- [Response Time](https://npmjs.com/package/response-time) => Response time header for Node.js
32+
- [Stripe](https://stripe.com/) => A suite of payment APIs that powers commerce for online businesses of all sizes
33+
- [vhost](https://npmjs.com/package/vhost) => Create an HTTP server for each virtual host
34+
- [Free APIs](https://free-apis.github.io/) => Free APIs for developers
35+
36+
## Contributing
37+
38+
If you would like to contribute to the project, please read the [CONTRIBUTING.md](CONTRIBUTING.md) file.
39+
40+
## License
41+
42+
This project is licensed under the Affero General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
43+
44+
## Code of Conduct
45+
46+
Please read the [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) file for details on our code of conduct.
47+
48+
## Contributors
49+
50+
We have a list of contributors [here](Contributors). If you would like to be added to the list, please read the [CONTRIBUTING.md](CONTRIBUTING.md) file.
51+
52+
## Contact
53+
54+
If you have any questions, please feel free to reach out to us at [[email protected]](mailto:[email protected]).

api/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const router = require('express').Router();
2+
const RateLimiter = require('../middleware/rateLimit')
23
require('dotenv').config();
34

45
const mainRoutes = require('./routes/router');
56

67
router
8+
.use(RateLimiter.main)
79
.use('/', mainRoutes);
810

911
module.exports = router;

api/routes/location.js

+18-34
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
11
const router = require('express').Router();
22

3-
const fullDataToLocationData = (data) => {
4-
const finalObj = {
5-
address: {
6-
full: '',
7-
houseNumber: '',
8-
street: '',
9-
city: '',
10-
region: '',
11-
country: '',
12-
postalCode: '',
13-
},
14-
pluscode: '',
15-
coords: {
16-
lat: '',
17-
lng: '',
18-
},
3+
const fullDataToLocationData = (data) => Object.assign({ address: { full: '', houseNumber: '', street: '', city: '', region: '', country: '', postalCode: '' }, pluscode: '', coords: { lat: '', lng: '' } }, {
4+
address: {
5+
full: data.results[0].formatted_address,
6+
houseNumber: (data.results[0].address_components).filter(a => a.types.includes('street_number'))[0]?.long_name,
7+
street: (data.results[0].address_components).filter(a => a.types.includes('route'))[0]?.long_name,
8+
city: (data.results[0].address_components).filter(a => a.types.includes('locality'))[0].long_name,
9+
region: (data.results[0].address_components).filter(a => a.types.includes('administrative_area_level_1'))[0].long_name,
10+
country: (data.results[0].address_components).filter(a => a.types.includes('country'))[0].long_name,
11+
postalCode: (data.results[0].address_components).filter(a => a.types.includes('postal_code'))[0].long_name,
12+
},
13+
pluscode: (data?.plus_code)?.global_code,
14+
coords: {
15+
lat: (data.results[0].geometry).location.lat,
16+
lng: (data.results[0].geometry).location.lng,
1917
}
20-
const address = data.results[0].address_components
21-
const geometry = data.results[0].geometry
22-
const pluscode = data?.plus_code
23-
finalObj.address.full = data.results[0].formatted_address
24-
finalObj.address.houseNumber = address.filter(a => a.types.includes('street_number'))[0]?.long_name
25-
finalObj.address.street = address.filter(a => a.types.includes('route'))[0]?.long_name
26-
finalObj.address.city = address.filter(a => a.types.includes('locality'))[0].long_name
27-
finalObj.address.region = address.filter(a => a.types.includes('administrative_area_level_1'))[0].long_name
28-
finalObj.address.country = address.filter(a => a.types.includes('country'))[0].long_name
29-
finalObj.address.postalCode = address.filter(a => a.types.includes('postal_code'))[0].long_name
30-
finalObj.pluscode = pluscode?.global_code
31-
finalObj.coords.lat = geometry.location.lat
32-
finalObj.coords.lng = geometry.location.lng
33-
return finalObj;
34-
}
18+
});
3519

3620
router
3721
.get('/coords', async (req, res) => {
@@ -46,7 +30,7 @@ router
4630
})
4731
const data = JSON.parse(results.data)
4832
if (data.status == 'ZERO_RESULTS') return res.sendError(13)
49-
res.json({data: fullDataToLocationData(data)});
33+
res.json({ data: fullDataToLocationData(data) });
5034
})
5135
.get('/pluscode', async (req, res) => {
5236
const pluscode = req.headers['x-pluscode']
@@ -60,7 +44,7 @@ router
6044
})
6145
const data = JSON.parse(results.data)
6246
if (data.status == 'ZERO_RESULTS') return res.sendError(13)
63-
res.json({data: fullDataToLocationData(data)});
47+
res.json({ data: fullDataToLocationData(data) });
6448
})
6549
.get('/address', async (req, res) => {
6650
const address = req.headers['x-address']
@@ -74,7 +58,7 @@ router
7458
})
7559
const data = JSON.parse(results.data)
7660
if (data.status == 'ZERO_RESULTS') return res.sendError(13)
77-
res.json({data: fullDataToLocationData(data)});
61+
res.json({ data: fullDataToLocationData(data) });
7862
})
7963
.use((req, res, next) => {
8064
const { path } = req;

core/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const router = require('express').Router();
2+
require('dotenv').config();
3+
4+
const routes = require('./routes/router');
5+
6+
router
7+
.use(router)
8+
9+
module.exports = router;

routes/ab.js core/routes/ab.js

File renamed without changes.

routes/errors.js core/routes/errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ router
3434
.get(`/501`, (req, res) => {
3535
res.render(
3636
`misc/501.pug`,
37-
req.getErrPage(501, { errorId: require(`../functions/util-fuctions`).Utils.Crypto.FullHash("Testing Error") })
37+
req.getErrPage(501, { errorId: require(`../../functions/util-fuctions`).Utils.Crypto.FullHash("Testing Error") })
3838
)
3939
})
4040
.get(`/location`, (req, res) => {
File renamed without changes.

routes/main.js core/routes/main.js

File renamed without changes.
File renamed without changes.
File renamed without changes.

routes/pay/router.js core/routes/pay/router.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const express = require('express')
22
const router = express.Router()
33
const { default: StripeSDK } = require('stripe')
44
const StripeInstance = new StripeSDK('sk_test_51O2gfrBeqjdZxel2weZc8YAOTGvnj15TCZzoFjr1kuM8nzvpAI7lGsXPW1mqamRXTZ3VWoISpdhTRUtC2v29Nf2l00JHlh2VkX')
5-
const TokenManager = require('../../functions/crypto');
5+
const TokenManager = require('../../../functions/crypto');
66

77
const payment = require('./pay')
88
const api = require('./api')

routes/router.js core/routes/router.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ const router = require('express').Router();
33
require('dotenv').config();
44

55
//- Routes
6-
const website = require('./main');
7-
const legal = require('./legal');
8-
const error = require('./errors');
9-
const ab = require('./ab');
6+
const website = require('./routes/main');
7+
const legal = require('./routes/legal');
8+
const error = require('./routes/errors');
9+
const ab = require('./routes/ab');
1010
const OSSProject = require('../oss/routes/project');
11-
const Payment = require('./pay/router')
11+
const Payment = require('./routes/pay/router')
1212

1313
//- Router setup
1414
router
File renamed without changes.

index.js

+7-22
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@ const cors = require('cors');
44
const vhost = require('vhost');
55
const crypto = require('crypto');
66
const Admin = require('firebase-admin');
7-
const { RateLimiterMemory } = require('rate-limiter-flexible');
87
require('dotenv').config();
98

10-
const RateLimiter = new RateLimiterMemory({
11-
points: 30,
12-
duration: 1,
13-
})
14-
159
//- Middleware
1610
const IPM = require('./middleware/IP'); //? IP Middleware
1711
const SM = require('./middleware/session'); //? Session Manager
18-
const MRL = require('./middleware/rateLimit')(RateLimiter); //? Rate Limiter
1912
const TRACE = require('./middleware/traceHandler'); //? Tracing Middleware
2013
const RL = require('./middleware/routeLogger'); //? Route Logger
2114
const Headers = require('./middleware/headers'); //? Header Setter
@@ -106,14 +99,7 @@ app
10699
ipData.hash === (
107100
function (data) {
108101
let currentHash = data;
109-
crypto.getHashes().forEach(
110-
hashAlg => {
111-
currentHash = crypto
112-
.createHash(hashAlg)
113-
.update(currentHash)
114-
.digest('base64url')
115-
}
116-
);
102+
crypto.getHashes().forEach(hashAlg => { currentHash = crypto.createHash(hashAlg).update(currentHash).digest('base64url') });
117103
return crypto
118104
.createHash('id-rsassa-pkcs1-v1_5-with-sha3-512')
119105
.update(currentHash)
@@ -134,15 +120,8 @@ app
134120
next();
135121
})
136122
.use(TRACE)
137-
.use(MRL)
138123
.use(Headers)
139124
.use(cors(CORSPerms))
140-
.use(vhost('api.thefemdevs.com', require('./api/')))
141-
.use(vhost('oss.thefemdevs.com', require('./oss/')))
142-
.use(vhost('cdn.thefemdevs.com', require('./cdn/')))
143-
.use(vhost('www.thefemdevs.com', require('./routes/router')))
144-
.use(vhost('thefemdevs.com', require('./routes/router')))
145-
.use(vhost('localhost', require('./routes/router')))
146125
.get(`/robots.txt`, (_, res) => {
147126
res
148127
.sendFile(`${process.cwd()}/metadata/robots.txt`)
@@ -152,6 +131,12 @@ app
152131
.setHeader(`Content-Type`, `text/xml`)
153132
.sendFile(`${process.cwd()}/metadata/sitemap.xml`)
154133
})
134+
.use(vhost('api.thefemdevs.com', require('./api/')))
135+
.use(vhost('oss.thefemdevs.com', require('./oss/')))
136+
.use(vhost('cdn.thefemdevs.com', require('./cdn/')))
137+
.use(vhost('*.thefemdevs.com', require('./core/')))
138+
.use(vhost('thefemdevs.com', require('./core/')))
139+
.use(vhost('localhost', require('./core/')))
155140
.use((req, res, next) => {
156141
const { path } = req;
157142
const methodUsed = req.method.toUpperCase();

0 commit comments

Comments
 (0)