GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DevStackBox/scripts/test-apache-overrides.mjs at main · DevStackBox/DevStackBox

Expand file tree

/

test-apache-overrides.mjs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
72 lines (71 loc) · 3.48 KB
/

test-apache-overrides.mjs

Copy path

File metadata and controls

72 lines (71 loc) · 3.48 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Isolated loopback regression test. Never reads or writes the installed config.
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { spawn, execFileSync } from 'node:child_process';
import net from 'node:net';
import assert from 'node:assert/strict';
const root = path.resolve(import.meta.dirname, '..');
const apache = path.join(root, 'apache/bin/httpd.exe');
const dir = mkdtempSync(path.join(tmpdir(), 'dsb-overrides-'));
const project = path.join(dir, 'Project with spaces');
mkdirSync(path.join(project, 'public'), { recursive: true });
writeFileSync(path.join(project, '.htaccess'), '<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteRule ^ index.php [L]\n</IfModule>\n');
writeFileSync(path.join(project, '.env'), 'PRIVATE_FIXTURE');
writeFileSync(path.join(project, 'public/.htaccess'), 'RewriteEngine On\nRewriteRule ^route$ ok.txt [L]\n');
writeFileSync(path.join(project, 'public/ok.txt'), 'rewrite worked');
const listener = net.createServer();
await new Promise(resolve => listener.listen(0, '127.0.0.1', resolve));
const port = listener.address().port;
await new Promise(resolve => listener.close(resolve));
const p = value => value.replaceAll('\\', '/');
const source = readFileSync(path.join(root, 'src-tauri/src/utils/apache_overrides.rs'), 'utf8');
const baseline = JSON.parse(source.match(/pub const BASELINE: &str = (".*");/)[1]);
const legacy = process.argv.includes('--legacy');
const config = `${legacy ? '' : baseline}
ServerRoot "${p(path.join(root, 'apache'))}"
Listen 127.0.0.1:${port}
ServerName localhost
PidFile "${p(path.join(dir, 'httpd.pid'))}"
ErrorLog "${p(path.join(dir, 'error.log'))}"
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule mime_module modules/mod_mime.so
TypesConfig "${p(path.join(root, 'apache/conf/mime.types'))}"
DocumentRoot "${p(path.join(project, 'public'))}"
<Directory "${p(path.join(project, 'public'))}">
Options +FollowSymLinks
AllowOverride All
Require local
</Directory>
`;
const file = path.join(dir, 'httpd.conf');
writeFileSync(file, config);
execFileSync(apache, ['-f', file, '-t'], { windowsHide: true });
const child = spawn(apache, ['-X', '-f', file], { windowsHide: true, stdio: 'ignore' });
try {
let ready = false;
for (let i = 0; i < 40; i++) {
try { await fetch(`http://127.0.0.1:${port}/ok.txt`); ready = true; break; }
catch { await new Promise(resolve => setTimeout(resolve, 100)); }
}
assert.ok(ready, 'Isolated Apache did not start');
if (legacy) {
assert.equal((await fetch(`http://127.0.0.1:${port}/route`)).status, 500);
assert.match(readFileSync(path.join(dir, 'error.log'), 'utf8'), /IfModule not allowed here/);
console.log('PASS: reproduced original parent .htaccess failure without the baseline.');
} else {
for (const resource of ['route', 'ok.txt']) {
const response = await fetch(`http://127.0.0.1:${port}/${resource}`);
assert.equal(response.status, 200);
assert.equal(await response.text(), 'rewrite worked');
}
assert.equal((await fetch(`http://127.0.0.1:${port}/.env`)).status, 404);
console.log('PASS: parent .htaccess ignored, public rewrites and assets work, private parent file inaccessible.');
}
} finally {
child.kill();
await new Promise(resolve => child.exitCode !== null ? resolve() : child.once('exit', resolve));
console.log(`Diagnostic fixture retained at ${dir}`);
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.