type IContact = {
id: string;
first: string;
last: string;
avatar: string;
twitter: string;
note: string;
favorite: boolean;
}
export function getContact(id: string): Promise<IContact> {
const getTimeout = () => Math.floor(Math.random() * 1000)
return new Promise((resolve) => {
setTimeout(() => {
resolve(createRandomContact(id))
}, getTimeout())
})
}
try_files $uri
и всё?location /user {
try_files $uri /user.php$is_args$args;
}
location ~ ^/user-list\.js(/|$) {
и здесь уже делать запрос на node js сервер для обработки по апи loselhost/user-list
}
export interface LoaderFunctionArgs extends DataFunctionArgs {
}
interface DataFunctionArgs {
request: Request;
params: Params;
context?: any;
}
export type Params<Key extends string = string> = {
readonly [key in Key]: string | undefined;
};
export const loader:LoaderFunction = async (args: LoaderFunctionArgs) => {
const contact = await getContact(args.params.id)
return contact
}
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
function loader(params: TParams)
Type '(params: TParams) => Promise<IContact>' is not assignable to type 'LoaderFunction'.
Types of parameters 'params' and 'args' are incompatible.
Property 'id' is missing in type 'LoaderFunctionArgs' but required in type 'TParams'.
params.id
строку