surge-client
v1.1.0
Published
client for surge.sh
Downloads
2
Readme
Surge-Client
Init
import SurgeClient from "surge-client";
const client = new SurgeClient({
proxy: "proxy.com", // the proxy server host, you can use vercel-proxy // cus surge is not support CORS originally
onError: (err: Error) => {
// the global error handler
console.log(err);
},
});
Login
await client
.login({
email: "",
password: "",
})
.catch((err: Error) => {
console.log(err);
});
Logout
await client.logout();
publish
const files: Record<string, string> = {
"dir/index.html": `<h1>Hello World!!!</h1>`,
"dir/css/style.css": `html,body{margin:0}`,
"dir/js/js.js": `console.log("js.js");`,
"dir/level1/level2/text.txt": "text",
};
await client
.publish({
files,
domain: "domain.surge.sh",
onProgress: ({
id,
progress,
file,
}: {
id: string;
progress: number;
file: string;
}) => {
console.log({ id, progress, file });
},
onTick: (tick: string) => {},
})
.catch((err: Error) => {
console.log(err);
});
Whoami
await client.whoami().catch((err: Error) => {
console.log(err);
});
List
await client.list().catch((err: Error) => {
console.log(err);
});
Teardown (UnPublish)
await client.teardown("domain.surge.sh").catch((err: Error) => {
console.log(err);
});
Get Surge Token
console.log(client.token);
Handle UnAuth Error
import SurgeClient, { notLoginEnum } from "src";
const client = new SurgeClient({
proxy: "https://proxy.com",
onError: (err) => {
if (err.message === notLoginEnum) {
// handle Not Login
}
},
});