-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle-api.js
More file actions
27 lines (25 loc) · 1017 Bytes
/
toggle-api.js
File metadata and controls
27 lines (25 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const fs = require('fs');
const path = require('path');
const apiPath = path.join(__dirname, 'src/app/api');
const apiBackupPath = path.join(__dirname, 'src/app/api_disabled');
const middlewarePath = path.join(__dirname, 'middleware.ts');
const middlewareBackupPath = path.join(__dirname, 'middleware.ts.bak');
if (process.argv[2] === 'disable') {
if (fs.existsSync(apiPath)) {
fs.renameSync(apiPath, apiBackupPath);
console.log('API routes disabled for static export.');
}
if (fs.existsSync(middlewarePath)) {
fs.renameSync(middlewarePath, middlewareBackupPath);
console.log('Middleware disabled for static export.');
}
} else if (process.argv[2] === 'enable') {
if (fs.existsSync(apiBackupPath)) {
fs.renameSync(apiBackupPath, apiPath);
console.log('API routes re-enabled.');
}
if (fs.existsSync(middlewareBackupPath)) {
fs.renameSync(middlewareBackupPath, middlewarePath);
console.log('Middleware re-enabled.');
}
}