Back to Templates

EdgeOne Pages MySQL Template

A full-stack application template based on EdgeOne Pages and Next.js, supporting MySQL database connections, allowing you to deploy production-level applications without managing servers.

View Demo
A full-stack application template based on EdgeOne Pages and Next.js, supporting MySQL database connections, allowing you to deploy production-level applications without managing servers.

EdgeOne Pages MySQL Template

A full-stack application template based on EdgeOne Pages and Next.js, supporting MySQL database connections, allowing you to deploy production-level applications without managing servers.

โœจ Features

  • ๐Ÿš€ Serverless Architecture - Based on EdgeOne Pages Node Functions, no server management required
  • ๐Ÿ—„๏ธ MySQL Integration - Built-in database connection pool and query executor
  • โšก Modern Frontend - Next.js 15 + React 19 + TypeScript
  • ๐ŸŽจ Beautiful UI - Tailwind CSS 4 + Responsive Design
  • ๐Ÿ”ง Out-of-the-Box - Preconfigured development environment and build process
  • ๐Ÿ“ฑ Mobile-First - Fully responsive design, supporting all devices

๐Ÿ› ๏ธ Tech Stack

Frontend

  • Next.js 15.4.6 - React full-stack framework
  • React 19.1.0 - User interface library
  • TypeScript 5 - Type-safe JavaScript
  • Tailwind CSS 4 - Utility-first CSS framework

Backend

  • EdgeOne Pages - Edge computing platform
  • Node Functions - Serverless function runtime
  • MySQL2 - MySQL database driver

Development Tools

  • ESLint - Code quality checker
  • PostCSS - CSS postprocessor
  • Turbopack - Fast build tool

๐Ÿš€ Quick Start

Environment Requirements

  • Node.js 18.0 or higher
  • MySQL 5.7 or higher
  • EdgeOne Pages account

Install Dependencies

# Clone the project
git clone <your-repo-url>
cd mysql-template

# Install dependencies
npm install

Environment Configuration

Create a .env.local file and configure the database connection:

# Database configuration
DB_HOST=your-mysql-host
DB_PORT=3306
DB_USER=your-username
DB_PASSWORD=your-password
DB_NAME=your-database-name

Local Development

# Start the development server
edgeone pages dev

# Access http://localhost:8088

Build and Deployment

# Build the production version
edgeone pages build

๐Ÿ“š API Documentation

Database Query API

Endpoint: /db
Method: GET
Function: Executes MySQL query and returns the result

Response Format:

{
  "success": true,
  "data": [...],
  "error": null,
  "thisis": "get"
}

Example Request:

curl -X GET https://your-domain.com/db

Custom Query

Modify the SQL statement in the node-functions/db.js file:

// Modify the query logic
const result = await executeQuery('SELECT * FROM your_table LIMIT 100');

๐Ÿ—„๏ธ Database Configuration

MySQL Connection Configuration

The project uses a connection pool to manage database connections, supporting the following configurations:

const dbConfig = {
  host: process.env.DB_HOST,
  port: process.env.DB_PORT || 3306,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  charset: 'utf8mb4',
  timezone: '+08:00',
  connectionLimit: 10,
  acquireTimeout: 60000,
  timeout: 60000,
  reconnect: true
};

Database Table Structure

Ensure your MySQL database has the corresponding table structure. Example:

๐Ÿ—๏ธ Project Structure

mysql-template/
โ”œโ”€โ”€ src/                    # Source code directory
โ”‚   โ”œโ”€โ”€ app/               # Next.js App Router
โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx     # Root layout component
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx       # Home page component
โ”‚   โ”‚   โ””โ”€โ”€ globals.css    # Global styles
โ”‚   โ”œโ”€โ”€ components/        # React components
โ”‚   โ”‚   โ””โ”€โ”€ ui/           # UI component library
โ”‚   โ””โ”€โ”€ lib/              # Utility functions
โ”œโ”€โ”€ node-functions/        # EdgeOne Pages functions
โ”‚   โ””โ”€โ”€ db.js            # Database operation function
โ”œโ”€โ”€ public/               # Static resources
โ”œโ”€โ”€ package.json          # Project configuration
โ”œโ”€โ”€ next.config.ts        # Next.js configuration
โ”œโ”€โ”€ tailwind.config.js    # Tailwind CSS configuration
โ””โ”€โ”€ tsconfig.json         # TypeScript configuration

๐Ÿ”ง Development Guide

Adding a New API Endpoint

Create a new .js file in the node-functions/ directory:

export const onRequestGet = async (context) => {
  // Handle GET request
  return new Response(JSON.stringify({ message: "Hello World" }), {
    headers: { 'Content-Type': 'application/json' }
  });
};

export const onRequestPost = async (context) => {
  // Handle POST request
  const body = await context.request.json();
  return new Response(JSON.stringify({ received: body }), {
    headers: { 'Content-Type': 'application/json' }
  });
};

Customizing Styles

The project uses Tailwind CSS 4, and you can add custom styles in src/app/globals.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
  .custom-button {
    @apply bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded;
  }
}

๐Ÿ› Troubleshooting

Common Issues

Database Connection Failure

  • Check environment variable configurations
  • Confirm MySQL service status
  • Verify network connection and firewall settings

Build Error

  • Clean up node_modules and .next directories
  • Reinstall dependencies: npm install
  • Check TypeScript type errors

API Call Failure

  • Check EdgeOne Pages function deployment status
  • View function log output
  • Confirm database table structure

๐Ÿ“„ License

This project uses the MIT License - see the LICENSE file for details.