SSG-menu.js
Overview
The SSG-menu.js
file defines two primary routes for a static site generator (SSG) management system:
- Authentication Routes (
/auth
): Handles user authentication to secure access to the SSG menu. - SSR Menu Routes (
/ssr-menu
): Facilitates listing website pages and regenerating them via server-side rendering (SSR).
These routes ensure controlled and secure access to SSG tools, while enabling efficient page management.
Content
Routes
/auth
Endpoints
-
/
:- Behavior:
- Returns the login page as an HTML file.
- Example:
Response:GET /auth/
- 200: HTML content of the login page.
- Behavior:
-
/login
:- Behavior:
- Authenticates the user using the GudHub API.
- Validates the user's
auth_key
against the website'sauth_key
. - Sets an
accesstoken
cookie if authentication is successful.
- Example:
Response:POST /auth/login Content-Type: application/json { "username": "admin", "password": "password123" }
- 200:
{ "message": "Login successful" }
(on success). - 401:
Unauthorized: Invalid credentials
. - 403:
Forbidden: Invalid authentication key
.
- 200:
- Behavior:
/ssr-menu
Endpoints
-
/
:- Behavior:
- Serves the SSR menu page as an HTML file.
- Example:
Response:GET /ssr-menu/
- 200: HTML content of the SSR menu page.
- Behavior:
-
/pages-list
:- Behavior:
- Fetches the list of pages from the website’s sitemap located at
<protocol>://<host>/pages-sitemap.xml
. - Returns the list of page URLs as JSON.
- Fetches the list of pages from the website’s sitemap located at
- Example:
Response:GET /ssr-menu/pages-list
- 200: JSON array of page URLs.
[ "https://example.com/page1", "https://example.com/page2" ]
- 500:
{ "error": "Internal server error" }
.
- 200: JSON array of page URLs.
- Behavior:
-
/generate-pages
:- Behavior:
- Initiates the SSR process to regenerate pages specified in the request body.
- Prevents concurrent SSR processes.
- Returns the results of the SSR process.
- Example:
Response:POST /ssr-menu/generate-pages Content-Type: application/json { "items": [ "https://example.com/page1", "https://example.com/page2" ] }
- 200: JSON with SSR results.
[ { "site": "https://example.com/page", "status": "Done", "duration": "2.1s", "valid": "true", "time": "finish date" } ]
- 400:
{ "message": "Invalid input" }
. - 409:
{ "message": "Another SSR process is running" }
. - 500:
{ "message": "An error occurred during the SSR process" }
.
- 200: JSON with SSR results.
- Behavior:
Middleware
authenticateToken
:- Behavior:
- Ensures users are authenticated before accessing sensitive SSR menu endpoints.
- Usage:
Expected Behavior:router.use('/generate-pages', authenticateToken);
- If the user is authenticated, the request proceeds to the endpoint.
- If the user is unauthenticated, the server responds with
401 Unauthorized
.
- Behavior: