appstage 0.3.1 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +32 -0
- package/package.json +3 -6
- package/index.ts +0 -32
- package/src/controllers/files.ts +0 -250
- package/src/controllers/redirect.ts +0 -29
- package/src/controllers/unhandledError.ts +0 -15
- package/src/controllers/unhandledRoute.ts +0 -14
- package/src/lib/lang/getEffectiveLocale.ts +0 -52
- package/src/lib/lang/getLocales.ts +0 -10
- package/src/lib/lang/toLanguage.ts +0 -3
- package/src/lib/logger/LogOptions.ts +0 -8
- package/src/lib/logger/ansiEscapeCodes.ts +0 -6
- package/src/lib/logger/levelColors.ts +0 -4
- package/src/lib/logger/log.ts +0 -82
- package/src/middleware/init.ts +0 -22
- package/src/middleware/lang.ts +0 -83
- package/src/middleware/requestEvents.ts +0 -29
- package/src/scripts/bin.ts +0 -40
- package/src/scripts/build.ts +0 -80
- package/src/scripts/cli.ts +0 -43
- package/src/scripts/const/commonBuildOptions.ts +0 -13
- package/src/scripts/const/entryExtensions.ts +0 -1
- package/src/scripts/types/BuildParams.ts +0 -22
- package/src/scripts/utils/buildClient.ts +0 -42
- package/src/scripts/utils/buildServer.ts +0 -36
- package/src/scripts/utils/buildServerCSS.ts +0 -40
- package/src/scripts/utils/createPostbuildPlugins.ts +0 -66
- package/src/scripts/utils/getEntries.ts +0 -22
- package/src/scripts/utils/getEntryPoints.ts +0 -25
- package/src/scripts/utils/getFirstAvailable.ts +0 -22
- package/src/scripts/utils/setEntriesExport.ts +0 -30
- package/src/scripts/utils/toImportPath.ts +0 -12
- package/src/types/Controller.ts +0 -4
- package/src/types/ErrorController.ts +0 -3
- package/src/types/LogEventPayload.ts +0 -12
- package/src/types/LogLevel.ts +0 -1
- package/src/types/Middleware.ts +0 -7
- package/src/types/MiddlewareSet.ts +0 -3
- package/src/types/RenderStatus.ts +0 -9
- package/src/types/ReqCtx.ts +0 -11
- package/src/types/TransformContent.ts +0 -11
- package/src/types/express.d.ts +0 -15
- package/src/types/global.d.ts +0 -19
- package/src/utils/createApp.ts +0 -45
- package/src/utils/cspNonce.ts +0 -6
- package/src/utils/emitLog.ts +0 -18
- package/src/utils/getEntries.ts +0 -22
- package/src/utils/getServerURL.ts +0 -38
- package/src/utils/getStatusMessage.ts +0 -5
- package/src/utils/injectNonce.ts +0 -7
- package/src/utils/renderStatus.ts +0 -20
- package/src/utils/serializeState.ts +0 -3
- package/src/utils/servePipeableStream.ts +0 -32
- package/tsconfig.json +0 -19
package/src/utils/createApp.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import EventEmitter from "node:events";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import { log } from "../lib/logger/log.ts";
|
|
4
|
-
import { init } from "../middleware/init.ts";
|
|
5
|
-
import { requestEvents } from "../middleware/requestEvents.ts";
|
|
6
|
-
import type { LogEventPayload } from "../types/LogEventPayload.ts";
|
|
7
|
-
import { emitLog } from "./emitLog.ts";
|
|
8
|
-
import { getServerURL } from "./getServerURL.ts";
|
|
9
|
-
import { renderStatus } from "./renderStatus.ts";
|
|
10
|
-
|
|
11
|
-
export function createApp(callback?: () => void | Promise<void>) {
|
|
12
|
-
let app = express();
|
|
13
|
-
|
|
14
|
-
if (!app.events) app.events = new EventEmitter();
|
|
15
|
-
|
|
16
|
-
let listen = () => {
|
|
17
|
-
let { href, protocol, hostname, port } = getServerURL();
|
|
18
|
-
|
|
19
|
-
if (protocol === "http:")
|
|
20
|
-
app.listen(port, hostname, () => {
|
|
21
|
-
emitLog(
|
|
22
|
-
app,
|
|
23
|
-
`Server running at ${href} (NODE_ENV=${process.env.NODE_ENV})`,
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
if (process.env.NODE_ENV === "development")
|
|
29
|
-
app.events?.on("log", ({ message, ...payload }: LogEventPayload) => {
|
|
30
|
-
log(message, payload);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if (!app.renderStatus) app.renderStatus = renderStatus;
|
|
34
|
-
|
|
35
|
-
app.disable("x-powered-by");
|
|
36
|
-
app.use(init());
|
|
37
|
-
app.use(requestEvents());
|
|
38
|
-
|
|
39
|
-
let callbackResult = typeof callback === "function" ? callback() : null;
|
|
40
|
-
|
|
41
|
-
if (callbackResult instanceof Promise) callbackResult.then(listen);
|
|
42
|
-
else listen();
|
|
43
|
-
|
|
44
|
-
return app;
|
|
45
|
-
}
|
package/src/utils/cspNonce.ts
DELETED
package/src/utils/emitLog.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Application } from "express";
|
|
2
|
-
import type { LogEventPayload } from "../types/LogEventPayload.ts";
|
|
3
|
-
|
|
4
|
-
export function emitLog(
|
|
5
|
-
app: Application,
|
|
6
|
-
message?: LogEventPayload["message"] | LogEventPayload,
|
|
7
|
-
payload?: LogEventPayload,
|
|
8
|
-
) {
|
|
9
|
-
let normalizedPayload: LogEventPayload = {
|
|
10
|
-
timestamp: Date.now(),
|
|
11
|
-
...payload,
|
|
12
|
-
...(typeof message === "string" || message instanceof Error
|
|
13
|
-
? { message }
|
|
14
|
-
: message),
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return app.events?.emit("log", normalizedPayload);
|
|
18
|
-
}
|
package/src/utils/getEntries.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { lstat, readdir } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
|
|
4
|
-
export async function getEntries() {
|
|
5
|
-
let cwd = process.cwd();
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
let list = await readdir(join(cwd, "src/entries"));
|
|
9
|
-
|
|
10
|
-
let dirs = await Promise.all(
|
|
11
|
-
list.map(async (name) => {
|
|
12
|
-
let itemStat = await lstat(join(cwd, "src/entries", name));
|
|
13
|
-
|
|
14
|
-
return itemStat.isDirectory() ? name : undefined;
|
|
15
|
-
}),
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
return dirs.filter((dir) => dir !== undefined);
|
|
19
|
-
} catch {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const defaultPorts: Record<string, number> = {
|
|
2
|
-
"http:": 80,
|
|
3
|
-
"https:": 443,
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export function getServerURL() {
|
|
7
|
-
let {
|
|
8
|
-
SERVER_URL: href,
|
|
9
|
-
SERVER_HOSTNAME: hostname = "localhost",
|
|
10
|
-
SERVER_PORT: port = "3000",
|
|
11
|
-
} = process.env;
|
|
12
|
-
|
|
13
|
-
let protocol = "http:";
|
|
14
|
-
|
|
15
|
-
if (href) {
|
|
16
|
-
if (href.startsWith("//")) href = `${protocol}${href}`;
|
|
17
|
-
else if (!href.includes("://")) href = `${protocol}//${href}`;
|
|
18
|
-
else protocol = href.slice(0, href.indexOf("://") + 1);
|
|
19
|
-
|
|
20
|
-
let matches = href.match(/^\w+:\/\/([^/:]+)(:(\d+))?(\/|$)/);
|
|
21
|
-
|
|
22
|
-
if (matches?.[1]) hostname = matches[1];
|
|
23
|
-
if (matches?.[3]) port = matches[3];
|
|
24
|
-
} else href = `${protocol}//${hostname}:${port}`;
|
|
25
|
-
|
|
26
|
-
let parsedPort = Number(port);
|
|
27
|
-
let origin = `${protocol}//${hostname}`;
|
|
28
|
-
|
|
29
|
-
if (parsedPort !== defaultPorts[protocol]) origin += `:${port}`;
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
href,
|
|
33
|
-
origin,
|
|
34
|
-
protocol,
|
|
35
|
-
hostname,
|
|
36
|
-
port: parsedPort,
|
|
37
|
-
};
|
|
38
|
-
}
|
package/src/utils/injectNonce.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { STATUS_CODES } from "node:http";
|
|
2
|
-
import type { RenderStatus } from "../types/RenderStatus.ts";
|
|
3
|
-
|
|
4
|
-
export const renderStatus: RenderStatus = async (req, res) => {
|
|
5
|
-
let { id, nonce } = req.ctx;
|
|
6
|
-
let statusText = `${res.statusCode} ${STATUS_CODES[res.statusCode]}`;
|
|
7
|
-
let date = `${new Date().toISOString().replace(/T/, " ").replace(/Z$/, "")} UTC`;
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
"<!DOCTYPE html>" +
|
|
11
|
-
'<html><head><meta charset="utf-8"/>' +
|
|
12
|
-
'<meta name="viewport" content="width=device-width"/>' +
|
|
13
|
-
`<title>${statusText}</title>` +
|
|
14
|
-
`<style${nonce ? ` nonce="${nonce}"` : ""}>` +
|
|
15
|
-
"body{text-align:center;}</style></head>" +
|
|
16
|
-
`<body><h1>${statusText}</h1><hr/><p>` +
|
|
17
|
-
(id ? `<code>ID: ${id}</code><br/>` : "") +
|
|
18
|
-
`<code>${date}</code></p></body></html>`
|
|
19
|
-
);
|
|
20
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Request, Response } from "express";
|
|
2
|
-
import { emitLog } from "./emitLog.ts";
|
|
3
|
-
import { getStatusMessage } from "./getStatusMessage.ts";
|
|
4
|
-
|
|
5
|
-
type PipeableStream = {
|
|
6
|
-
pipe: <Writable extends NodeJS.WritableStream>(
|
|
7
|
-
destination: Writable,
|
|
8
|
-
) => Writable;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export function servePipeableStream(req: Request, res: Response) {
|
|
12
|
-
return async ({ pipe }: PipeableStream, error?: unknown) => {
|
|
13
|
-
let statusCode = error ? 500 : 200;
|
|
14
|
-
|
|
15
|
-
emitLog(req.app, getStatusMessage("Stream", statusCode), {
|
|
16
|
-
level: error ? "error" : undefined,
|
|
17
|
-
req,
|
|
18
|
-
res,
|
|
19
|
-
data: error,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
res.status(statusCode);
|
|
23
|
-
|
|
24
|
-
if (statusCode >= 400) {
|
|
25
|
-
res.send(await req.app.renderStatus?.(req, res));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
res.set("Content-Type", "text/html");
|
|
30
|
-
pipe(res);
|
|
31
|
-
};
|
|
32
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": ["./index.ts", "./src"],
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"emitDeclarationOnly": true,
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"lib": ["ESNext"],
|
|
8
|
-
"types": ["node", "express"],
|
|
9
|
-
"target": "ESNext",
|
|
10
|
-
"module": "nodenext",
|
|
11
|
-
"moduleResolution": "nodenext",
|
|
12
|
-
"allowImportingTsExtensions": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"allowSyntheticDefaultImports": true,
|
|
15
|
-
"strict": true,
|
|
16
|
-
"noUnusedLocals": true,
|
|
17
|
-
"noUnusedParameters": true
|
|
18
|
-
}
|
|
19
|
-
}
|