astro 1.6.7 → 1.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/app/index.js +2 -2
- package/dist/core/build/generate.js +5 -5
- package/dist/core/build/vite-plugin-hoisted-scripts.js +4 -1
- package/dist/core/build/vite-plugin-ssr.js +8 -3
- package/dist/core/config/schema.d.ts +2 -2
- package/dist/core/config/schema.js +14 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +1 -0
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/route-cache.js +3 -1
- package/dist/core/render/ssr-element.d.ts +4 -4
- package/dist/core/render/ssr-element.js +12 -12
- package/dist/core/routing/manifest/create.js +8 -4
- package/dist/vite-plugin-astro-server/base.js +2 -1
- package/dist/vite-plugin-astro-server/plugin.js +4 -2
- package/dist/vite-plugin-astro-server/request.js +21 -5
- package/dist/vite-plugin-astro-server/route.d.ts +9 -7
- package/dist/vite-plugin-astro-server/route.js +6 -0
- package/package.json +3 -3
package/dist/core/app/index.js
CHANGED
|
@@ -167,7 +167,7 @@ renderPage_fn = async function(request, routeData, mod, status = 200) {
|
|
|
167
167
|
const url = new URL(request.url);
|
|
168
168
|
const manifest = __privateGet(this, _manifest);
|
|
169
169
|
const info = __privateGet(this, _routeDataToRouteInfo).get(routeData);
|
|
170
|
-
const links = createLinkStylesheetElementSet(info.links
|
|
170
|
+
const links = createLinkStylesheetElementSet(info.links);
|
|
171
171
|
let scripts = /* @__PURE__ */ new Set();
|
|
172
172
|
for (const script of info.scripts) {
|
|
173
173
|
if ("stage" in script) {
|
|
@@ -178,7 +178,7 @@ renderPage_fn = async function(request, routeData, mod, status = 200) {
|
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
180
|
} else {
|
|
181
|
-
scripts.add(createModuleScriptElement(script
|
|
181
|
+
scripts.add(createModuleScriptElement(script));
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
try {
|
|
@@ -4,7 +4,6 @@ import { bgGreen, black, cyan, dim, green, magenta } from "kleur/colors";
|
|
|
4
4
|
import npath from "path";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
6
|
import {
|
|
7
|
-
joinPaths,
|
|
8
7
|
prependForwardSlash,
|
|
9
8
|
removeLeadingForwardSlash,
|
|
10
9
|
removeTrailingForwardSlash
|
|
@@ -179,16 +178,17 @@ function getUrlForPath(pathname, base, origin, format, routeType) {
|
|
|
179
178
|
return url;
|
|
180
179
|
}
|
|
181
180
|
async function generatePath(pathname, opts, gopts) {
|
|
182
|
-
var _a;
|
|
183
181
|
const { settings, logging, origin, routeCache } = opts;
|
|
184
182
|
const { mod, internals, linkIds, scripts: hoistedScripts, pageData, renderers } = gopts;
|
|
185
183
|
if (pageData.route.type === "page") {
|
|
186
184
|
addPageName(pathname, opts);
|
|
187
185
|
}
|
|
188
186
|
debug("build", `Generating: ${pathname}`);
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
|
|
187
|
+
const links = createLinkStylesheetElementSet(linkIds, settings.config.base);
|
|
188
|
+
const scripts = createModuleScriptsSet(
|
|
189
|
+
hoistedScripts ? [hoistedScripts] : [],
|
|
190
|
+
settings.config.base
|
|
191
|
+
);
|
|
192
192
|
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
193
193
|
const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID);
|
|
194
194
|
if (typeof hashedFilePath !== "string") {
|
|
@@ -29,7 +29,10 @@ function vitePluginHoistedScripts(settings, internals) {
|
|
|
29
29
|
},
|
|
30
30
|
async generateBundle(_options, bundle) {
|
|
31
31
|
var _a, _b;
|
|
32
|
-
let assetInlineLimit =
|
|
32
|
+
let assetInlineLimit = 4096;
|
|
33
|
+
if (((_a = settings.config.vite) == null ? void 0 : _a.build) && settings.config.vite.build.assetsInlineLimit !== void 0) {
|
|
34
|
+
assetInlineLimit = (_b = settings.config.vite) == null ? void 0 : _b.build.assetsInlineLimit;
|
|
35
|
+
}
|
|
33
36
|
for (const [id, output] of Object.entries(bundle)) {
|
|
34
37
|
if (output.type === "chunk" && output.facadeModuleId && virtualHoistedEntry(output.facadeModuleId)) {
|
|
35
38
|
const canBeInlined = output.imports.length === 0 && output.dynamicImports.length === 0 && Buffer.byteLength(output.code) <= assetInlineLimit;
|
|
@@ -105,16 +105,21 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
105
105
|
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
106
106
|
staticFiles.push(entryModules[PAGE_SCRIPT_ID]);
|
|
107
107
|
}
|
|
108
|
+
const bareBase = removeTrailingForwardSlash(removeLeadingForwardSlash(settings.config.base));
|
|
109
|
+
const joinBase = (pth) => bareBase ? bareBase + "/" + pth : pth;
|
|
108
110
|
for (const pageData of eachPageData(internals)) {
|
|
109
111
|
const scripts = [];
|
|
110
112
|
if (pageData.hoistedScript) {
|
|
111
|
-
scripts.unshift(
|
|
113
|
+
scripts.unshift(
|
|
114
|
+
Object.assign({}, pageData.hoistedScript, {
|
|
115
|
+
value: joinBase(pageData.hoistedScript.value)
|
|
116
|
+
})
|
|
117
|
+
);
|
|
112
118
|
}
|
|
113
119
|
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
114
120
|
scripts.push({ type: "external", value: entryModules[PAGE_SCRIPT_ID] });
|
|
115
121
|
}
|
|
116
|
-
const
|
|
117
|
-
const links = sortedCSS(pageData).map((pth) => bareBase ? bareBase + "/" + pth : pth);
|
|
122
|
+
const links = sortedCSS(pageData).map((pth) => joinBase(pth));
|
|
118
123
|
routes.push({
|
|
119
124
|
file: "",
|
|
120
125
|
links,
|
|
@@ -8,7 +8,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
8
8
|
publicDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
9
9
|
outDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
10
10
|
site: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
11
|
-
base: z.
|
|
11
|
+
base: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
12
12
|
trailingSlash: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"always">, z.ZodLiteral<"never">, z.ZodLiteral<"ignore">]>>>;
|
|
13
13
|
output: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"static">, z.ZodLiteral<"server">]>>>;
|
|
14
14
|
adapter: z.ZodOptional<z.ZodObject<{
|
|
@@ -239,7 +239,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
239
239
|
publicDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
240
240
|
outDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
241
241
|
site: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
242
|
-
base: z.
|
|
242
|
+
base: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
243
243
|
trailingSlash: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"always">, z.ZodLiteral<"never">, z.ZodLiteral<"ignore">]>>>;
|
|
244
244
|
output: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"static">, z.ZodLiteral<"server">]>>>;
|
|
245
245
|
adapter: z.ZodOptional<z.ZodObject<{
|
|
@@ -47,7 +47,7 @@ const AstroConfigSchema = z.object({
|
|
|
47
47
|
publicDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => new URL(val)),
|
|
48
48
|
outDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(val)),
|
|
49
49
|
site: z.string().url().optional().transform((val) => val ? appendForwardSlash(val) : val),
|
|
50
|
-
base: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.base)
|
|
50
|
+
base: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.base),
|
|
51
51
|
trailingSlash: z.union([z.literal("always"), z.literal("never"), z.literal("ignore")]).optional().default(ASTRO_CONFIG_DEFAULTS.trailingSlash),
|
|
52
52
|
output: z.union([z.literal("static"), z.literal("server")]).optional().default("static"),
|
|
53
53
|
adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
|
|
@@ -171,6 +171,19 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
|
|
|
171
171
|
if (!config.build.client.toString().startsWith(config.outDir.toString()) && config.build.client.toString().endsWith("dist/client/")) {
|
|
172
172
|
config.build.client = new URL("./dist/client/", config.outDir);
|
|
173
173
|
}
|
|
174
|
+
const trimmedBase = trimSlashes(config.base);
|
|
175
|
+
const sitePathname = config.site && new URL(config.site).pathname;
|
|
176
|
+
if (!trimmedBase.length && sitePathname && sitePathname !== "/") {
|
|
177
|
+
config.base = sitePathname;
|
|
178
|
+
console.warn(`The site configuration value includes a pathname of ${sitePathname} but there is no base configuration.
|
|
179
|
+
|
|
180
|
+
A future version of Astro will stop using the site pathname when producing <link> and <script> tags. Set your site's base with the base configuration.`);
|
|
181
|
+
}
|
|
182
|
+
if (trimmedBase.length && config.trailingSlash === "never") {
|
|
183
|
+
config.base = prependForwardSlash(trimmedBase);
|
|
184
|
+
} else {
|
|
185
|
+
config.base = prependForwardSlash(appendForwardSlash(trimmedBase));
|
|
186
|
+
}
|
|
174
187
|
return config;
|
|
175
188
|
});
|
|
176
189
|
return AstroConfigRelativeSchema;
|
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -38,6 +38,7 @@ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs
|
|
|
38
38
|
const astroPkgsConfig = await crawlFrameworkPkgs({
|
|
39
39
|
root: fileURLToPath(settings.config.root),
|
|
40
40
|
isBuild: mode === "build",
|
|
41
|
+
viteUserConfig: settings.config.vite,
|
|
41
42
|
isFrameworkPkgByJson(pkgJson) {
|
|
42
43
|
var _a, _b, _c, _d;
|
|
43
44
|
return ((_a = pkgJson.peerDependencies) == null ? void 0 : _a.astro) || ((_b = pkgJson.dependencies) == null ? void 0 : _b.astro) || ((_c = pkgJson.keywords) == null ? void 0 : _c.includes("astro")) || ((_d = pkgJson.keywords) == null ? void 0 : _d.includes("astro-component")) || /^(@[^\/]+\/)?astro\-/.test(pkgJson.name);
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -30,7 +30,7 @@ async function dev(settings, options) {
|
|
|
30
30
|
isRestart: options.isRestart
|
|
31
31
|
})
|
|
32
32
|
);
|
|
33
|
-
const currentVersion = "1.6.
|
|
33
|
+
const currentVersion = "1.6.8";
|
|
34
34
|
if (currentVersion.includes("-")) {
|
|
35
35
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
36
36
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.6.
|
|
50
|
+
const version = "1.6.8";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -264,7 +264,7 @@ function printHelp({
|
|
|
264
264
|
message.push(
|
|
265
265
|
linebreak(),
|
|
266
266
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
267
|
-
`v${"1.6.
|
|
267
|
+
`v${"1.6.8"}`
|
|
268
268
|
)} ${headline}`
|
|
269
269
|
);
|
|
270
270
|
}
|
|
@@ -24,10 +24,12 @@ async function callGetStaticPaths({
|
|
|
24
24
|
throw new AstroError(AstroErrorData.GetStaticPathsDeprecatedRSS);
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
|
+
if (Array.isArray(staticPaths)) {
|
|
28
|
+
staticPaths = staticPaths.flat();
|
|
29
|
+
}
|
|
27
30
|
if (isValidate) {
|
|
28
31
|
validateGetStaticPathsResult(staticPaths, logging, route);
|
|
29
32
|
}
|
|
30
|
-
staticPaths = staticPaths.flat();
|
|
31
33
|
const keyedStaticPaths = staticPaths;
|
|
32
34
|
keyedStaticPaths.keyed = /* @__PURE__ */ new Map();
|
|
33
35
|
for (const sp of keyedStaticPaths) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { SSRElement } from '../../@types/astro';
|
|
2
|
-
export declare function createLinkStylesheetElement(href: string,
|
|
3
|
-
export declare function createLinkStylesheetElementSet(hrefs: string[],
|
|
2
|
+
export declare function createLinkStylesheetElement(href: string, base?: string): SSRElement;
|
|
3
|
+
export declare function createLinkStylesheetElementSet(hrefs: string[], base?: string): Set<SSRElement>;
|
|
4
4
|
export declare function createModuleScriptElement(script: {
|
|
5
5
|
type: 'inline' | 'external';
|
|
6
6
|
value: string;
|
|
7
|
-
},
|
|
7
|
+
}, base?: string): SSRElement;
|
|
8
8
|
export declare function createModuleScriptElementWithSrc(src: string, site?: string): SSRElement;
|
|
9
9
|
export declare function createModuleScriptElementWithSrcSet(srces: string[], site?: string): Set<SSRElement>;
|
|
10
10
|
export declare function createModuleScriptsSet(scripts: {
|
|
11
11
|
type: 'inline' | 'external';
|
|
12
12
|
value: string;
|
|
13
|
-
}[],
|
|
13
|
+
}[], base?: string): Set<SSRElement>;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import npath from "path-browserify";
|
|
2
2
|
import { appendForwardSlash } from "../../core/path.js";
|
|
3
|
-
function getRootPath(
|
|
4
|
-
return appendForwardSlash(new URL(
|
|
3
|
+
function getRootPath(base) {
|
|
4
|
+
return appendForwardSlash(new URL(base || "/", "http://localhost/").pathname);
|
|
5
5
|
}
|
|
6
|
-
function joinToRoot(href,
|
|
7
|
-
return npath.posix.join(getRootPath(
|
|
6
|
+
function joinToRoot(href, base) {
|
|
7
|
+
return npath.posix.join(getRootPath(base), href);
|
|
8
8
|
}
|
|
9
|
-
function createLinkStylesheetElement(href,
|
|
9
|
+
function createLinkStylesheetElement(href, base) {
|
|
10
10
|
return {
|
|
11
11
|
props: {
|
|
12
12
|
rel: "stylesheet",
|
|
13
|
-
href: joinToRoot(href,
|
|
13
|
+
href: joinToRoot(href, base)
|
|
14
14
|
},
|
|
15
15
|
children: ""
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
function createLinkStylesheetElementSet(hrefs,
|
|
19
|
-
return new Set(hrefs.map((href) => createLinkStylesheetElement(href,
|
|
18
|
+
function createLinkStylesheetElementSet(hrefs, base) {
|
|
19
|
+
return new Set(hrefs.map((href) => createLinkStylesheetElement(href, base)));
|
|
20
20
|
}
|
|
21
|
-
function createModuleScriptElement(script,
|
|
21
|
+
function createModuleScriptElement(script, base) {
|
|
22
22
|
if (script.type === "external") {
|
|
23
|
-
return createModuleScriptElementWithSrc(script.value,
|
|
23
|
+
return createModuleScriptElementWithSrc(script.value, base);
|
|
24
24
|
} else {
|
|
25
25
|
return {
|
|
26
26
|
props: {
|
|
@@ -42,8 +42,8 @@ function createModuleScriptElementWithSrc(src, site) {
|
|
|
42
42
|
function createModuleScriptElementWithSrcSet(srces, site) {
|
|
43
43
|
return new Set(srces.map((src) => createModuleScriptElementWithSrc(src, site)));
|
|
44
44
|
}
|
|
45
|
-
function createModuleScriptsSet(scripts,
|
|
46
|
-
return new Set(scripts.map((script) => createModuleScriptElement(script,
|
|
45
|
+
function createModuleScriptsSet(scripts, base) {
|
|
46
|
+
return new Set(scripts.map((script) => createModuleScriptElement(script, base)));
|
|
47
47
|
}
|
|
48
48
|
export {
|
|
49
49
|
createLinkStylesheetElement,
|
|
@@ -35,7 +35,7 @@ function getParts(part, file) {
|
|
|
35
35
|
});
|
|
36
36
|
return result;
|
|
37
37
|
}
|
|
38
|
-
function getPattern(segments, addTrailingSlash) {
|
|
38
|
+
function getPattern(segments, base, addTrailingSlash) {
|
|
39
39
|
const pathname = segments.map((segment) => {
|
|
40
40
|
if (segment.length === 1 && segment[0].spread) {
|
|
41
41
|
return "(?:\\/(.*?))?";
|
|
@@ -52,7 +52,11 @@ function getPattern(segments, addTrailingSlash) {
|
|
|
52
52
|
}
|
|
53
53
|
}).join("");
|
|
54
54
|
const trailing = addTrailingSlash && segments.length ? getTrailingSlashPattern(addTrailingSlash) : "$";
|
|
55
|
-
|
|
55
|
+
let initial = "\\/";
|
|
56
|
+
if (addTrailingSlash === "never" && base !== "/") {
|
|
57
|
+
initial = "";
|
|
58
|
+
}
|
|
59
|
+
return new RegExp(`^${pathname || initial}${trailing}`);
|
|
56
60
|
}
|
|
57
61
|
function getTrailingSlashPattern(addTrailingSlash) {
|
|
58
62
|
if (addTrailingSlash === "always") {
|
|
@@ -209,7 +213,7 @@ function createRouteManifest({ settings, cwd, fsMod }, logging) {
|
|
|
209
213
|
components.push(item.file);
|
|
210
214
|
const component = item.file;
|
|
211
215
|
const trailingSlash = item.isPage ? settings.config.trailingSlash : "never";
|
|
212
|
-
const pattern = getPattern(segments, trailingSlash);
|
|
216
|
+
const pattern = getPattern(segments, settings.config.base, trailingSlash);
|
|
213
217
|
const generate = getRouteGenerator(segments, trailingSlash);
|
|
214
218
|
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
|
215
219
|
const route = `/${segments.map(([{ dynamic, content }]) => dynamic ? `[${content}]` : content).join("/")}`.toLowerCase();
|
|
@@ -251,7 +255,7 @@ function createRouteManifest({ settings, cwd, fsMod }, logging) {
|
|
|
251
255
|
const type = resolved.endsWith(".astro") ? "page" : "endpoint";
|
|
252
256
|
const isPage = type === "page";
|
|
253
257
|
const trailingSlash = isPage ? config.trailingSlash : "never";
|
|
254
|
-
const pattern = getPattern(segments, trailingSlash);
|
|
258
|
+
const pattern = getPattern(segments, settings.config.base, trailingSlash);
|
|
255
259
|
const generate = getRouteGenerator(segments, trailingSlash);
|
|
256
260
|
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
|
257
261
|
const params = segments.flat().filter((p) => p.dynamic).map((p) => p.content);
|
|
@@ -8,12 +8,13 @@ function baseMiddleware(settings, logging) {
|
|
|
8
8
|
const site = config.site ? new URL(config.base, config.site) : void 0;
|
|
9
9
|
const devRootURL = new URL(config.base, "http://localhost");
|
|
10
10
|
const devRoot = site ? site.pathname : devRootURL.pathname;
|
|
11
|
+
const devRootReplacement = devRoot.endsWith("/") ? "/" : "";
|
|
11
12
|
return function devBaseMiddleware(req, res, next) {
|
|
12
13
|
var _a;
|
|
13
14
|
const url = req.url;
|
|
14
15
|
const pathname = decodeURI(new URL(url, "http://localhost").pathname);
|
|
15
16
|
if (pathname.startsWith(devRoot)) {
|
|
16
|
-
req.url = url.replace(devRoot,
|
|
17
|
+
req.url = url.replace(devRoot, devRootReplacement);
|
|
17
18
|
return next();
|
|
18
19
|
}
|
|
19
20
|
if (pathname === "/" || pathname === "/index.html") {
|
|
@@ -33,8 +33,10 @@ function createVitePluginAstroServer({
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
viteServer.middlewares.use(async (req, res) => {
|
|
36
|
-
if (
|
|
37
|
-
|
|
36
|
+
if (req.url === void 0 || !req.method) {
|
|
37
|
+
res.writeHead(500, "Incomplete request");
|
|
38
|
+
res.end();
|
|
39
|
+
return;
|
|
38
40
|
}
|
|
39
41
|
handleRequest(env, manifest, serverController, req, res);
|
|
40
42
|
});
|
|
@@ -2,18 +2,23 @@ import { collectErrorMetadata } from "../core/errors/dev/index.js";
|
|
|
2
2
|
import { createSafeError } from "../core/errors/index.js";
|
|
3
3
|
import { error } from "../core/logger/core.js";
|
|
4
4
|
import * as msg from "../core/messages.js";
|
|
5
|
+
import { removeTrailingForwardSlash } from "../core/path.js";
|
|
5
6
|
import { runWithErrorHandling } from "./controller.js";
|
|
6
7
|
import { handle500Response } from "./response.js";
|
|
7
8
|
import { handleRoute, matchRoute } from "./route.js";
|
|
8
9
|
async function handleRequest(env, manifest, controller, req, res) {
|
|
9
|
-
var _a;
|
|
10
10
|
const { settings, loader: moduleLoader } = env;
|
|
11
11
|
const { config } = settings;
|
|
12
12
|
const origin = `${moduleLoader.isHttps() ? "https" : "http"}://${req.headers.host}`;
|
|
13
13
|
const buildingToSSR = config.output === "server";
|
|
14
|
-
const url = new URL(origin +
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const url = new URL(origin + req.url);
|
|
15
|
+
let pathname;
|
|
16
|
+
if (config.trailingSlash === "never" && !req.url) {
|
|
17
|
+
pathname = "";
|
|
18
|
+
} else {
|
|
19
|
+
pathname = decodeURI(url.pathname);
|
|
20
|
+
}
|
|
21
|
+
url.pathname = removeTrailingForwardSlash(config.base) + url.pathname;
|
|
17
22
|
if (!buildingToSSR && pathname !== "/_image") {
|
|
18
23
|
const allSearchParams = Array.from(url.searchParams);
|
|
19
24
|
for (const [key] of allSearchParams) {
|
|
@@ -36,7 +41,18 @@ async function handleRequest(env, manifest, controller, req, res) {
|
|
|
36
41
|
pathname,
|
|
37
42
|
async run() {
|
|
38
43
|
const matchedRoute = await matchRoute(pathname, env, manifest);
|
|
39
|
-
|
|
44
|
+
const resolvedPathname = (matchedRoute == null ? void 0 : matchedRoute.resolvedPathname) ?? pathname;
|
|
45
|
+
return await handleRoute(
|
|
46
|
+
matchedRoute,
|
|
47
|
+
url,
|
|
48
|
+
resolvedPathname,
|
|
49
|
+
body,
|
|
50
|
+
origin,
|
|
51
|
+
env,
|
|
52
|
+
manifest,
|
|
53
|
+
req,
|
|
54
|
+
res
|
|
55
|
+
);
|
|
40
56
|
},
|
|
41
57
|
onError(_err) {
|
|
42
58
|
const err = createSafeError(_err);
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type http from 'http';
|
|
3
|
-
import type { ManifestData } from '../@types/astro';
|
|
4
|
-
import { DevelopmentEnvironment } from '../core/render/dev/index';
|
|
3
|
+
import type { ComponentInstance, ManifestData, RouteData } from '../@types/astro';
|
|
4
|
+
import { ComponentPreload, DevelopmentEnvironment } from '../core/render/dev/index';
|
|
5
5
|
declare type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (...args: any) => Promise<infer R> ? R : any;
|
|
6
|
-
|
|
7
|
-
route:
|
|
6
|
+
interface MatchedRoute {
|
|
7
|
+
route: RouteData;
|
|
8
8
|
filePath: URL;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
resolvedPathname: string;
|
|
10
|
+
preloadedComponent: ComponentPreload;
|
|
11
|
+
mod: ComponentInstance;
|
|
12
|
+
}
|
|
13
|
+
export declare function matchRoute(pathname: string, env: DevelopmentEnvironment, manifest: ManifestData): Promise<MatchedRoute | undefined>;
|
|
12
14
|
export declare function handleRoute(matchedRoute: AsyncReturnType<typeof matchRoute>, url: URL, pathname: string, body: ArrayBuffer | undefined, origin: string, env: DevelopmentEnvironment, manifest: ManifestData, req: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
|
|
13
15
|
export {};
|
|
@@ -36,11 +36,16 @@ async function matchRoute(pathname, env, manifest) {
|
|
|
36
36
|
return {
|
|
37
37
|
route: maybeRoute,
|
|
38
38
|
filePath,
|
|
39
|
+
resolvedPathname: pathname,
|
|
39
40
|
preloadedComponent,
|
|
40
41
|
mod
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
}
|
|
45
|
+
const altPathname = pathname.replace(/(index)?\.html$/, "");
|
|
46
|
+
if (altPathname !== pathname) {
|
|
47
|
+
return await matchRoute(altPathname, env, manifest);
|
|
48
|
+
}
|
|
44
49
|
if (matches.length) {
|
|
45
50
|
const possibleRoutes = matches.flatMap((route) => route.component);
|
|
46
51
|
warn(
|
|
@@ -62,6 +67,7 @@ ${AstroErrorData.NoMatchingStaticPathFound.hint(possibleRoutes)}`
|
|
|
62
67
|
return {
|
|
63
68
|
route: custom404,
|
|
64
69
|
filePath,
|
|
70
|
+
resolvedPathname: pathname,
|
|
65
71
|
preloadedComponent,
|
|
66
72
|
mod
|
|
67
73
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.8",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"vendor"
|
|
88
88
|
],
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@astrojs/compiler": "^0.29.
|
|
90
|
+
"@astrojs/compiler": "^0.29.15",
|
|
91
91
|
"@astrojs/language-server": "^0.28.3",
|
|
92
92
|
"@astrojs/markdown-remark": "^1.1.3",
|
|
93
93
|
"@astrojs/telemetry": "^1.0.1",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"unist-util-visit": "^4.1.0",
|
|
146
146
|
"vfile": "^5.3.2",
|
|
147
147
|
"vite": "~3.2.1",
|
|
148
|
-
"vitefu": "^0.
|
|
148
|
+
"vitefu": "^0.2.0",
|
|
149
149
|
"yargs-parser": "^21.0.1",
|
|
150
150
|
"zod": "^3.17.3"
|
|
151
151
|
},
|