[now dev] Add support for handle: miss and handle: hit (#3537)

- [x] Add tests from now-proxy for `handle: miss`
- [x] Add tests from now-proxy for `handle: hit`
- [x] Add file output renaming when `featHandleMiss` is true (also assign true for now dev)
This commit is contained in:
Steven
2020-01-21 19:54:24 -05:00
committed by kodiakhq[bot]
parent dd36a489ed
commit 5dd2daa970
49 changed files with 712 additions and 122 deletions

View File

@@ -3,11 +3,22 @@ import { BuilderParams, BuildResult, ShouldServeParams } from './types';
export const version = 2;
export function build({ files, entrypoint }: BuilderParams): BuildResult {
export function build({
files,
entrypoint,
config,
}: BuilderParams): BuildResult {
let path = entrypoint;
const outputDir = config.zeroConfig ? config.outputDirectory : '';
const outputMatch = outputDir + '/';
if (outputDir && path.startsWith(outputMatch)) {
// static output files are moved to the root directory
path = path.slice(outputMatch.length);
}
const output = {
[entrypoint]: files[entrypoint],
[path]: files[entrypoint],
};
const watch = [entrypoint];
const watch = [path];
return { output, routes: [], watch };
}
@@ -16,14 +27,25 @@ export function shouldServe({
entrypoint,
files,
requestPath,
config = {},
}: ShouldServeParams) {
let outputPrefix = '';
const outputDir = config.zeroConfig ? config.outputDirectory : '';
const outputMatch = outputDir + '/';
if (outputDir && entrypoint.startsWith(outputMatch)) {
// static output files are moved to the root directory
entrypoint = entrypoint.slice(outputMatch.length);
outputPrefix = outputMatch;
}
const isMatch = (f: string) => entrypoint === f && outputPrefix + f in files;
if (isIndex(entrypoint)) {
const indexPath = join(requestPath, basename(entrypoint));
if (entrypoint === indexPath && indexPath in files) {
if (isMatch(indexPath)) {
return true;
}
}
return entrypoint === requestPath && requestPath in files;
return isMatch(requestPath);
}
function isIndex(path: string): boolean {