-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require that ASTRO_STUDIO_REMOTE_DB_URL is defined at runtime (#10533)
* Require that ASTRO_STUDIO_REMOTE_DB_URL is defined at runtime * Add changeset * Fix build
- Loading branch information
Showing
12 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@astrojs/db": patch | ||
--- | ||
|
||
Ensure ASTRO_STUDIO_APP_TOKEN is found at runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import db from '@astrojs/db'; | ||
import { defineConfig } from 'astro/config'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [db()], | ||
devToolbar: { | ||
enabled: false, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { column, defineDb, defineTable } from 'astro:db'; | ||
|
||
|
||
const User = defineTable({ | ||
columns: { | ||
id: column.text({ primaryKey: true, optional: false }), | ||
username: column.text({ optional: false, unique: true }), | ||
password: column.text({ optional: false }), | ||
}, | ||
}); | ||
|
||
export default defineDb({ | ||
tables: { User }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export default function() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@test/db-no-apptoken", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "astro dev", | ||
"build": "astro build", | ||
"preview": "astro preview" | ||
}, | ||
"dependencies": { | ||
"@astrojs/db": "workspace:*", | ||
"astro": "workspace:*" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/db/test/fixtures/no-apptoken/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
/// <reference path="../../.astro/db-types.d.ts" /> | ||
import { db, User } from 'astro:db'; | ||
// Just for the side-effect of running all the code | ||
await db.select().from(User); | ||
--- | ||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
<h1>Testing</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expect } from 'chai'; | ||
import testAdapter from '../../astro/test/test-adapter.js'; | ||
import { loadFixture } from '../../astro/test/test-utils.js'; | ||
import { setupRemoteDbServer } from './test-utils.js'; | ||
|
||
describe('missing app token', () => { | ||
let fixture; | ||
let remoteDbServer; | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: new URL('./fixtures/no-apptoken/', import.meta.url), | ||
output: 'server', | ||
adapter: testAdapter(), | ||
}); | ||
|
||
remoteDbServer = await setupRemoteDbServer(fixture.config); | ||
await fixture.build(); | ||
// Ensure there's no token at runtime | ||
delete process.env.ASTRO_STUDIO_APP_TOKEN; | ||
}); | ||
|
||
after(async () => { | ||
await remoteDbServer?.stop(); | ||
}); | ||
|
||
it('Errors as runtime', async () => { | ||
const app = await fixture.loadTestAdapterApp(); | ||
const request = new Request('http://example.com/'); | ||
try { | ||
const response = await app.render(request); | ||
await response.text(); | ||
} catch { | ||
expect(response.status).to.equal(501); | ||
} | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.