-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OomsOoms
committed
Sep 19, 2024
1 parent
c2c5e0e
commit b69e0d7
Showing
2 changed files
with
173 additions
and
1 deletion.
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 |
---|---|---|
@@ -1 +1,64 @@ | ||
# nettleship.net | ||
# nettleship.net | ||
|
||
This repository contains the full stack codebase for the Nettleship.net website, including both the client and server components. | ||
|
||
This project began in Python a while ago, just so I could play Uno with my friends in class on our laptops. Websites like this already existed, but we wanted our own version that was fully customizable. I managed to get the Python version to a playable state, though the code itself could’ve been better. | ||
|
||
I later decided to restart the project in JavaScript, and in doing so, I researched best practices for professional APIs and frontends. My aim is to learn as much about web development as possible. | ||
|
||
While rewriting it, I’ve also been taking notes so I can use this code for my A Level Computer Science coursework. | ||
|
||
## Project Structure | ||
|
||
- `client/`: Contains the frontend code | ||
- `server/`: Contains the backend code | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
- Node.js v22.2.0 | ||
- npm | ||
- MongoDB | ||
|
||
### Installation | ||
|
||
1. Clone the repository: | ||
|
||
```sh | ||
git clone https://github.com/oomsooms/nettleship-net.git | ||
cd nettleship-net | ||
``` | ||
|
||
2. Install dependencies for both client and server: | ||
|
||
```sh | ||
cd client | ||
npm install | ||
cd ../server | ||
npm install | ||
``` | ||
|
||
## Running the Application | ||
|
||
### Client | ||
|
||
1. Navigate to the client directory: | ||
|
||
```sh | ||
cd client | ||
``` | ||
|
||
2. Start the development server: | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
3. The client will be running on http://localhost:3000. | ||
|
||
For server setup and running instructions, refer to the [server README](./server/README.md). | ||
|
||
## License | ||
|
||
This project is licensed under the GPL-3.0 License - see the [LICENSE](/LICENSE) file for details. |
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,109 @@ | ||
|
||
# Server | ||
|
||
This is the API backend for the Nettleship.net website, built with Express and MongoDB. | ||
|
||
## Project Structure | ||
|
||
- `src/`: Contains the main application code. | ||
- `tests/`: Contains unit and integration tests. | ||
- `logs/`: Contains log files. | ||
- `public/`: Contains public assets like uploads when in development. Production uses AWS S3 + cloudfront. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
- Node.js v22.2.0 | ||
- npm | ||
- MongoDB | ||
|
||
### Installation | ||
|
||
1. Clone the repository: | ||
|
||
```sh | ||
git clone https://github.com/oomsooms/nettleship-net.git | ||
cd nettleship-net/server | ||
``` | ||
|
||
2. Install dependencies: | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
3. Create a `.env` file based on `.env.example`: | ||
|
||
```sh | ||
cp .env.example .env | ||
``` | ||
|
||
4. Update the `.env` file with your configuration. | ||
|
||
### Environment Variables | ||
|
||
The `NODE_ENV` environment variable is used in several places throughout the codebase to determine the environment in which the application is running. Here is a list of its usages and their effects: | ||
|
||
1. **Logging Configuration**: | ||
- File: [src/config/logger.js](src/config/logger.js) | ||
- Effect: In non-production environments, only console logging is enabled. In production, file logging is used. | ||
|
||
2. **Request Validation**: | ||
- File: [src/api/middlewares/validateRequest.js](src/api/middlewares/validateRequest.js) | ||
- Effect: In production, a generic error message is returned for invalid requests. In other environments, detailed validation errors are returned. | ||
|
||
3. **Database Connection**: | ||
- File: [src/config/db.js](src/config/db.js) | ||
- Effect: In test environments, an in-memory MongoDB server is used. In other environments, the database URI from the environment variables is used. | ||
|
||
4. **Server Configuration**: | ||
- File: [src/app.js](src/app.js) | ||
- Effect: In production, HTTP request logs are written to a file. In other environments, logs are output to the console. | ||
|
||
### Running the Server | ||
|
||
1. Start the development server: | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
2. The server will be running on http://localhost:8000. | ||
|
||
### Testing | ||
|
||
I have used Jest for the server tests. | ||
|
||
Unit tests will mock all functions before the tests. | ||
Intergration tests will use MongoDB Memory Server. | ||
|
||
to run the tests: | ||
|
||
```sh | ||
npm test | ||
``` | ||
|
||
### Test Suites | ||
|
||
Here is an overview of what each test covers: | ||
|
||
- **Test name**: Test description | ||
|
||
(still need to redo tests before adding them here) | ||
|
||
### Linting | ||
|
||
I have used ESLint for linting. | ||
|
||
To lint the code: | ||
|
||
```sh | ||
npm run lint | ||
``` | ||
|
||
To automatically fix linting errors: | ||
|
||
```sh | ||
npm run lint:fix | ||
``` |