Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/api-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test API

on:
pull_request:
branches:
- develop
- main
paths:
- .github/workflows/api-test.yml
- api/**

jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
defaults:
run:
working-directory: api
steps:
- uses: actions/[email protected]
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '22.14.0'
- name: Install dependencies
run: npm ci
- name: Run build
run: npm run build
- name: Run ESLint
run: npm run lint
- name: Run Prettier
run: npm run format:check
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ This is a template for mobile app development using:

This is a template for building APIs using:

- [Go](https://go.dev/) // TODO: 選定して更新
- [Node.js](https://nodejs.org/) v22.14.0
- [Express](https://expressjs.com/)
- [TypeScript](https://www.typescriptlang.org/)
22 changes: 22 additions & 0 deletions api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'prettier'
],
plugins: ['@typescript-eslint', 'prettier'],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
node: true,
es6: true,
},
rules: {
'prettier/prettier': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-undef': 'off',
},
};
41 changes: 41 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Production build
dist/

# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Logs
logs/
*.log

# Runtime data
pids/
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage/

# TypeScript
*.tsbuildinfo
8 changes: 8 additions & 0 deletions api/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false
}
99 changes: 99 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,100 @@
# API

This is a template for building APIs using Node.js, Express, and TypeScript.

## Technology Stack

- [Node.js](https://nodejs.org/) v22.14.0
- [Express](https://expressjs.com/) - Web framework
- [TypeScript](https://www.typescriptlang.org/) - Type-safe JavaScript
- [Helmet](https://helmetjs.github.io/) - Security middleware
- [CORS](https://github.com/expressjs/cors) - Cross-origin resource sharing
- [Morgan](https://github.com/expressjs/morgan) - HTTP request logger

## Getting Started

### Prerequisites

- Node.js v22.14.0 or later
- npm or yarn

### Installation

```bash
npm install
```

### Development

Start the development server with hot reload:

```bash
npm run dev
```

The API will be available at `http://localhost:3000`

### Building

Build the TypeScript code:

```bash
npm run build
```

### Production

Run the production build:

```bash
npm start
```

## API Endpoints

### Health Check
- `GET /health` - Health check endpoint

### Main Routes
- `GET /` - API information
- `GET /api/users` - Get all users (sample)
- `POST /api/users` - Create a new user (sample)

## Development Commands

- `npm run dev` - Start development server with hot reload
- `npm run build` - Build TypeScript to JavaScript
- `npm start` - Start production server
- `npm run lint` - Run ESLint
- `npm run format` - Format code with Prettier
- `npm run format:check` - Check code formatting

## Project Structure

```
api/
├── src/
│ └── index.ts # Main server file
├── dist/ # Build output (generated)
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .eslintrc.js # ESLint configuration
├── .prettierrc # Prettier configuration
├── .gitignore # Git ignore rules
└── README.md # This file
```

## Environment Variables

Create a `.env` file in the root directory:

```
PORT=3000
NODE_ENV=development
```

## Adding New Routes

1. Create route files in the `src/` directory
2. Import and use them in `src/index.ts`
3. Follow the existing pattern for error handling and middleware
Loading