feat: add native Adminer database access
This commit is contained in:
@@ -7,6 +7,7 @@ import { promisify } from 'util'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
renderMariaDbConfig,
|
||||
renderNativeAdminerBootstrap,
|
||||
renderNginxConfig,
|
||||
renderPhpFpmConfig,
|
||||
startNativeProject,
|
||||
@@ -54,6 +55,16 @@ describe('native project configuration', () => {
|
||||
expect(config).toContain('port=41003')
|
||||
expect(config).toContain('/.aurora/native/data/mariadb')
|
||||
})
|
||||
it('creates a loopback Adminer endpoint with project database credentials', () => {
|
||||
expect(renderNginxConfig(project)).toContain('location = /__aurora/adminer/')
|
||||
const bootstrap = renderNativeAdminerBootstrap({
|
||||
...project,
|
||||
installedRuntimeRoot: '/tmp/aurora-runtime'
|
||||
})
|
||||
expect(bootstrap).toContain("value = '127.0.0.1:41003'")
|
||||
expect(bootstrap).toContain("username.value = 'db'")
|
||||
expect(bootstrap).toContain('/tmp/aurora-runtime/root/usr/share/aurora/adminer.php')
|
||||
})
|
||||
})
|
||||
|
||||
it.runIf(Boolean(process.env.AURORA_NATIVE_SMOKE_ROOT))(
|
||||
@@ -170,6 +181,15 @@ it.runIf(Boolean(process.env.AURORA_NATIVE_WORDPRESS_SMOKE_ROOT))(
|
||||
{ cwd: root, env: process.env }
|
||||
)
|
||||
expect(restored.stdout.trim()).toBe('Aurora native smoke')
|
||||
|
||||
const adminerResponse = await fetch(
|
||||
`http://127.0.0.1:${definition.ports.http}/__aurora/adminer/`
|
||||
)
|
||||
const adminerHtml = await adminerResponse.text()
|
||||
expect(adminerResponse.ok).toBe(true)
|
||||
expect(adminerHtml).toContain('Adminer')
|
||||
expect(adminerHtml).toContain("username.value = 'db'")
|
||||
expect(adminerHtml).toContain("value = '127.0.0.1:")
|
||||
} finally {
|
||||
await stopNativeProject(definition)
|
||||
}
|
||||
|
||||
@@ -68,6 +68,22 @@ http {
|
||||
server_name localhost;
|
||||
root "${quoteNginx(webroot)}";
|
||||
index index.php index.html;
|
||||
location = /__aurora/adminer/ {
|
||||
fastcgi_pass 127.0.0.1:${project.ports.php};
|
||||
fastcgi_param SCRIPT_FILENAME "${quoteNginx(join(directory, 'adminer.php'))}";
|
||||
fastcgi_param SCRIPT_NAME /__aurora/adminer/;
|
||||
fastcgi_param REQUEST_METHOD $request_method;
|
||||
fastcgi_param REQUEST_URI $request_uri;
|
||||
fastcgi_param QUERY_STRING $query_string;
|
||||
fastcgi_param CONTENT_TYPE $content_type;
|
||||
fastcgi_param CONTENT_LENGTH $content_length;
|
||||
fastcgi_param SERVER_PROTOCOL $server_protocol;
|
||||
fastcgi_param SERVER_NAME $server_name;
|
||||
fastcgi_param SERVER_PORT $server_port;
|
||||
fastcgi_param HTTP_HOST $http_host;
|
||||
fastcgi_param REMOTE_ADDR $remote_addr;
|
||||
fastcgi_param REMOTE_PORT $remote_port;
|
||||
}
|
||||
location / { try_files $uri $uri/ /index.php?$query_string; }
|
||||
location ~ \\.php$ {
|
||||
fastcgi_pass 127.0.0.1:${project.ports.php};
|
||||
@@ -92,6 +108,30 @@ http {
|
||||
`
|
||||
}
|
||||
|
||||
export function renderNativeAdminerBootstrap(project: NativeProjectDefinition): string {
|
||||
const adminer = join(installedRoot(project), 'root', 'usr', 'share', 'aurora', 'adminer.php')
|
||||
return `<?php
|
||||
// Generated by Aurora Core. This endpoint binds only to the project's loopback server.
|
||||
?>
|
||||
<script>
|
||||
addEventListener('DOMContentLoaded', () => {
|
||||
const username = document.querySelector('input[name="auth[username]"]');
|
||||
if (!username) return;
|
||||
const form = username.form;
|
||||
form.querySelector('input[name="auth[server]"]').value = '127.0.0.1:${project.ports.database}';
|
||||
username.value = 'db';
|
||||
form.querySelector('input[name="auth[password]"]').value = 'db';
|
||||
form.querySelector('input[name="auth[db]"]').value = 'db';
|
||||
const permanent = form.querySelector('input[name="auth[permanent]"]');
|
||||
if (permanent) permanent.checked = true;
|
||||
form.submit();
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
require '${adminer.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}';
|
||||
`
|
||||
}
|
||||
|
||||
export function renderMariaDbConfig(
|
||||
project: NativeProjectDefinition,
|
||||
installedRuntimeRoot = runtimeRoot()
|
||||
@@ -128,6 +168,7 @@ export async function provisionNativeProject(project: NativeProjectDefinition):
|
||||
await Promise.all([
|
||||
writeFile(join(directory, 'config', 'php-fpm.conf'), renderPhpFpmConfig(project)),
|
||||
writeFile(join(directory, 'config', 'nginx.conf'), renderNginxConfig(project)),
|
||||
writeFile(join(directory, 'adminer.php'), renderNativeAdminerBootstrap(project)),
|
||||
writeFile(
|
||||
join(directory, 'config', 'mariadb.cnf'),
|
||||
renderMariaDbConfig(project, installedRoot(project))
|
||||
|
||||
Reference in New Issue
Block a user