|
1 | | -# mdstream |
| 1 | +# mdstream (English) |
| 2 | + |
| 3 | +mdstream is a sample project consisting of a **React (Vite) + TypeScript** frontend and a **Serverless Framework (Node.js)** backend. It uses AWS S3 to store Markdown files and fetches them via HTTP APIs for listing and detail views in the web application. |
| 4 | + |
| 5 | + |
| 6 | +## Link |
| 7 | +[日本語版はこちら](./README.ja.md) |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +- **Frontend**: |
| 12 | + - Located under the `frontend/` directory, built with Vite + React + TypeScript. |
| 13 | + - Displays a list of Markdown files and their contents. |
| 14 | + - Also demonstrates how to load local markdown (e.g., `terms.md` and `privacy.md`) in the `/public/markdown/` folder and render it with React. |
| 15 | + |
| 16 | +- **Backend**: |
| 17 | + - Located under the `backend/` directory, built with the Serverless Framework on Node.js. |
| 18 | + - Fetches Markdown files from an S3 bucket and serves them via an HTTP API. |
| 19 | + - The environment variables (`BUCKET_NAME`, `ALLOWED_REFERER`, etc.) control where the Markdown files are stored and which referers are allowed. |
| 20 | + |
| 21 | +- **License**: |
| 22 | + - This project is published under **GNU General Public License (GPL) v3**. |
| 23 | + - See the `LICENSE` file for more details. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Directory Structure |
| 28 | + |
| 29 | +```bash |
| 30 | +mdstream/ |
| 31 | + ├─ frontend/ # React + Vite project |
| 32 | + │ ├─ public/markdown # Markdown files |
| 33 | + │ ├─ src/ # Source code (components, services, etc.) |
| 34 | + │ ├─ package.json |
| 35 | + │ ├─ vite.config.ts |
| 36 | + │ └─ ...other configs |
| 37 | + ├─ backend/ # Serverless Framework (Node.js) project |
| 38 | + │ ├─ src/ |
| 39 | + │ ├─ serverless.yml |
| 40 | + │ └─ package.json |
| 41 | + ├─ LICENSE |
| 42 | + └─ README.md (or README.ja.md for Japanese) |
| 43 | +``` |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Getting Started |
| 48 | + |
| 49 | +### 1. Clone the Repository |
| 50 | + |
| 51 | +```bash |
| 52 | +git clone https://github.com/yourname/mdstream.git |
| 53 | +cd mdstream |
| 54 | +``` |
| 55 | + |
| 56 | +### 2. Frontend Setup |
| 57 | + |
| 58 | +```bash |
| 59 | +cd frontend |
| 60 | +npm install |
| 61 | +``` |
| 62 | + |
| 63 | +- **Local Development** (connecting to a local API): |
| 64 | + ```bash |
| 65 | + npm run dev:local |
| 66 | + ``` |
| 67 | + - By default, the local dev server runs at [http://localhost:5173](http://localhost:5173). |
| 68 | + - It will load environment variables from `.env.dev` (or any `.env.*` specified). |
| 69 | +- **Build** |
| 70 | + ```bash |
| 71 | + npm run build:dev |
| 72 | + # or |
| 73 | + npm run build:prod |
| 74 | + ``` |
| 75 | + - The build output goes to `frontend/dist/`. |
| 76 | + |
| 77 | +### 3. Backend Setup |
| 78 | + |
| 79 | +```bash |
| 80 | +cd ../backend |
| 81 | +npm install |
| 82 | +``` |
| 83 | + |
| 84 | +- **Local Development (serverless-offline)**: |
| 85 | + ```bash |
| 86 | + npm run dev:local |
| 87 | + ``` |
| 88 | + - This will read environment variables such as `BUCKET_NAME` and `ALLOWED_REFERER` from `.env.dev` or similar. |
| 89 | + - The local serverless-offline endpoint (e.g., http://localhost:3000) will serve the API (depending on your `serverless.yml` config). |
| 90 | +- **Deploy to AWS Example**: |
| 91 | + ```bash |
| 92 | + npm run deploy:dev |
| 93 | + ``` |
| 94 | + - Requires your AWS credentials to be configured. |
| 95 | + - Deploys the backend as AWS Lambda functions. |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Editing / Adding Markdown Files |
| 100 | + |
| 101 | +- **Local** (frontend-based): |
| 102 | + - Simply place new `.md` files under `frontend/public/markdown/`. |
| 103 | + - Import or fetch them in your React components (like `PrivacyPage.tsx` or `TermsPage.tsx`). |
| 104 | +- **Backend (S3-based)**: |
| 105 | + - Upload your `.md` files to the appropriate S3 bucket. |
| 106 | + - Update environment variables (`S3_PREFIX`, etc.) to point to the correct location. |
| 107 | + - The `fetchMarkdownList` and `fetchMarkdownDetail` functions in `frontend/src/services/api.ts` call the API endpoints that read from S3. |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## Customization |
| 112 | + |
| 113 | +1. **Styling**: |
| 114 | + - Edit SCSS/CSS files in `frontend/src/styles/` to change the UI appearance. |
| 115 | +2. **Add Components**: |
| 116 | + - Create new React components in `frontend/src/components/`, and add corresponding routes in `App.tsx` as needed. |
| 117 | +3. **API Changes**: |
| 118 | + - Modify logic in `backend/src/handler.ts` or the `serverless.yml` file to adjust endpoints, environment variables, AWS settings, etc. |
| 119 | +4. **Dependencies**: |
| 120 | + - Update `frontend/package.json` or `backend/package.json` for any additional libraries. |
| 121 | + - Run `npm install` to install new dependencies. |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## Contributing |
| 126 | + |
| 127 | +- Please open an Issue for bugs or feature requests. |
| 128 | +- Pull requests are welcome. For major changes, consider discussing them in an Issue first. |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## License |
| 133 | + |
| 134 | +- Released under the **GNU GPL v3** license. |
| 135 | +- Refer to [LICENSE](./LICENSE) for details. |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## Contact |
| 140 | + |
| 141 | +- For questions or issues, please open an Issue or email [info@itc.tokyo](mailto:info@itc.tokyo). |
0 commit comments