Skip to content

Commit

Permalink
Use template literals + Move port to server block in config
Browse files Browse the repository at this point in the history
  • Loading branch information
xbubbo committed Nov 21, 2024
1 parent 74f4cd4 commit 91c525f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
6 changes: 4 additions & 2 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import type { Config } from "@/types/config";

const config: Config = {
// Server Configuration
port: 8080, // The port on which Interstellar runs (Default: 8080)
server: {
port: 8080, // The port on which Interstellar runs (Default: 8080)
},

// Authentication Configuration (Optional)
auth: {
Expand All @@ -13,7 +15,7 @@ const config: Config = {
// Format: username: "password",
// IMPORTANT: Replace default credentials before deployment
users: {
interstellar: "password",
interstellar: "password",
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function Start() {
}
}

const port = INConfig.port || 8080;
const port = INConfig.server?.port || 8080;

const app = Fastify({
serverFactory: (handler) =>
Expand Down
16 changes: 10 additions & 6 deletions randomize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "node:fs";
import path from "node:path";

const RenamedFiles: { [key: string]: string } = {};
const PageRoutes: { [key: string]: string } = {};
const PageRoutes: { [key: string]: string } = {};

export function randomizeName(filePath: string): string {
const extname = path.extname(filePath);
Expand Down Expand Up @@ -49,9 +49,13 @@ export function RandomizeNames() {
fs.renameSync(oldPath, newPath);

if (file.startsWith(path.join(process.cwd(), "src", "pages"))) {
const oldRoute = oldPath.replace(process.cwd() + "/src/pages", "").replace(/\\/g, "/");
const newRoute = newPath.replace(process.cwd() + "/src/pages", "").replace(/\\/g, "/");
PageRoutes[oldRoute] = newRoute;
const oldRoute = oldPath
.replace(`${process.cwd()}/src/pages`, "")
.replace(/\\/g, "/");
const newRoute = newPath
.replace(`${process.cwd()}/src/pages`, "")
.replace(/\\/g, "/");
PageRoutes[oldRoute] = newRoute;
}
}

Expand Down Expand Up @@ -112,7 +116,7 @@ export function updatePageRoutes() {
for (const [oldRoute, newRoute] of Object.entries(PageRoutes)) {
fileContent = fileContent.replace(
new RegExp(`['"]${oldRoute.replace(".astro", "")}['"]`, "g"),
`'${newRoute.replace(".astro", "")}'`
`'${newRoute.replace(".astro", "")}'`,
);
}

Expand All @@ -133,7 +137,7 @@ export async function Revert() {
try {
console.log("Reverting Changes.");
execSync("git restore src/", { cwd: process.cwd(), stdio: "inherit" });
execSync("git clean -fdx src/", { cwd: process.cwd(), stdio: "inherit" });
execSync("git clean -fdx src/", { cwd: process.cwd(), stdio: "inherit" });

await new Promise((resolve) => setTimeout(resolve, 2000));
console.log("Revert completed.");
Expand Down
31 changes: 16 additions & 15 deletions src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// Configuration for the application
export interface Config {
// Server configuration
server?: {
// The port to run the HTTP server on
// Default: 8080
port?: number;
};

// Authentication configuration
auth?: Auth;
/**
* The port to run the HTTP server on
* @default 8080
*/
port?: number;
}

// Authentication settings
export interface Auth {
/**
* Enable password protection
* @default false
*/
// Enable password protection
// Default: false
challenge?: boolean;
/**
* Users and their passwords
* @example ```js
{ "interstellarskidder": "superSecretPassword!!!" }
```
*/

// Users and their passwords
// Example: "username": "password",
users?: Record<string, string>;
}

0 comments on commit 91c525f

Please sign in to comment.