-
-
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.
* Adapter v0 * Finalizing adapters * Update the lockfile * Add the default adapter after config setup is called * Create the default adapter in config:done * Fix lint error * Remove unused callConfigSetup * remove unused export * Use a test adapter to test SSR * Adds a changeset * Updated based on feedback * Updated the lockfile * Only throw if set to a different adapter * Clean up outdated comments * Move the adapter to an config option * Make adapter optional * Update the docs/changeset to reflect config API change * Clarify regular Node usage
- Loading branch information
Showing
29 changed files
with
886 additions
and
496 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,29 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Adds support for the Node adapter (SSR) | ||
|
||
This provides the first SSR adapter available using the `integrations` API. It is a Node.js adapter that can be used with the `http` module or any framework that wraps it, like Express. | ||
|
||
In your astro.config.mjs use: | ||
|
||
```js | ||
import nodejs from '@astrojs/node'; | ||
|
||
export default { | ||
adapter: nodejs() | ||
} | ||
``` | ||
|
||
After performing a build there will be a `dist/server/entry.mjs` module that works like a middleware function. You can use with any framework that supports the Node `request` and `response` objects. For example, with Express you can do: | ||
|
||
```js | ||
import express from 'express'; | ||
import { handler as ssrHandler } from '@astrojs/node'; | ||
|
||
const app = express(); | ||
app.use(handler); | ||
|
||
app.listen(8080); | ||
``` |
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 was deleted.
Oops, something went wrong.
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,23 @@ | ||
import type { AstroAdapter, AstroIntegration } from '../@types/astro'; | ||
|
||
export function getAdapter(): AstroAdapter { | ||
return { | ||
name: '@astrojs/ssg', | ||
// This one has no server entrypoint and is mostly just an integration | ||
//serverEntrypoint: '@astrojs/ssg/server.js', | ||
}; | ||
} | ||
|
||
export default function createIntegration(): AstroIntegration { | ||
return { | ||
name: '@astrojs/ssg', | ||
hooks: { | ||
'astro:config:done': ({ setAdapter }) => { | ||
setAdapter(getAdapter()); | ||
}, | ||
'astro:build:start': ({ buildConfig }) => { | ||
buildConfig.staticMode = true; | ||
} | ||
} | ||
}; | ||
} |
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,64 @@ | ||
import type { AstroConfig, RouteType } from '../../@types/astro'; | ||
import npath from 'path'; | ||
import { appendForwardSlash } from '../../core/path.js'; | ||
|
||
const STATUS_CODE_PAGES = new Set(['/404', '/500']); | ||
|
||
export function getOutRoot(astroConfig: AstroConfig): URL { | ||
return new URL('./', astroConfig.dist); | ||
} | ||
|
||
export function getServerRoot(astroConfig: AstroConfig): URL { | ||
const rootFolder = getOutRoot(astroConfig); | ||
const serverFolder = new URL('./server/', rootFolder); | ||
return serverFolder; | ||
} | ||
|
||
export function getClientRoot(astroConfig: AstroConfig): URL { | ||
const rootFolder = getOutRoot(astroConfig); | ||
const serverFolder = new URL('./client/', rootFolder); | ||
return serverFolder; | ||
} | ||
|
||
export function getOutFolder(astroConfig: AstroConfig, pathname: string, routeType: RouteType): URL { | ||
const outRoot = getOutRoot(astroConfig); | ||
|
||
// This is the root folder to write to. | ||
switch (routeType) { | ||
case 'endpoint': | ||
return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot); | ||
case 'page': | ||
switch (astroConfig.buildOptions.pageUrlFormat) { | ||
case 'directory': { | ||
if (STATUS_CODE_PAGES.has(pathname)) { | ||
return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot); | ||
} | ||
return new URL('.' + appendForwardSlash(pathname), outRoot); | ||
} | ||
case 'file': { | ||
return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function getOutFile(astroConfig: AstroConfig, outFolder: URL, pathname: string, routeType: RouteType): URL { | ||
switch (routeType) { | ||
case 'endpoint': | ||
return new URL(npath.basename(pathname), outFolder); | ||
case 'page': | ||
switch (astroConfig.buildOptions.pageUrlFormat) { | ||
case 'directory': { | ||
if (STATUS_CODE_PAGES.has(pathname)) { | ||
const baseName = npath.basename(pathname); | ||
return new URL('./' + (baseName || 'index') + '.html', outFolder); | ||
} | ||
return new URL('./index.html', outFolder); | ||
} | ||
case 'file': { | ||
const baseName = npath.basename(pathname); | ||
return new URL('./' + (baseName || 'index') + '.html', outFolder); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.