mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 13:21:42 +03:00
Resolve port-data-source functions directly instead of writing them to cache.
This commit is contained in:
parent
e0d949c008
commit
91d009e70d
@ -53,11 +53,6 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
|
||||
const portsHash = (portsFile && portsFile.match(/-([^-]+)\.js$/)[1]) || "";
|
||||
const responsePath = fullPath(portsHash, request, hasFsAccess);
|
||||
|
||||
// TODO check cache expiration time and delete and go to else if expired
|
||||
if (useCache && (await checkFileExists(fs, responsePath))) {
|
||||
// console.log("Skipping request, found file.");
|
||||
resolve({ kind: "cache-response-path", value: responsePath });
|
||||
} else {
|
||||
let portBackendTask = {};
|
||||
let portBackendTaskImportError = null;
|
||||
try {
|
||||
@ -113,14 +108,9 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
const portFunctionResult = await portBackendTask[portName](input);
|
||||
await fs.promises.writeFile(
|
||||
responsePath,
|
||||
JSON.stringify(jsonResponse(portFunctionResult))
|
||||
);
|
||||
resolve({
|
||||
kind: "cache-response-path",
|
||||
value: responsePath,
|
||||
kind: "response-json",
|
||||
value: jsonResponse(await portBackendTask[portName](input)),
|
||||
});
|
||||
} catch (portCallError) {
|
||||
resolve({
|
||||
@ -206,14 +196,11 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
|
||||
console.trace("@@@ request-cache2 HTTP error", error);
|
||||
reject({
|
||||
title: "BackendTask.Http Error",
|
||||
message: `${kleur
|
||||
.yellow()
|
||||
.underline(request.url)} ${error.toString()}
|
||||
message: `${kleur.yellow().underline(request.url)} ${error.toString()}
|
||||
`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user