mirror of
https://github.com/NebulaServices/Nebula.git
synced 2025-05-17 13:30:00 -04:00
move wisp to plugin, remove build rq for running api
This commit is contained in:
parent
77dbccfc7e
commit
d70ff2f4cf
5 changed files with 101 additions and 77 deletions
|
@ -5,43 +5,46 @@ import tailwind from "@astrojs/tailwind";
|
||||||
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
|
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
|
||||||
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
|
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
|
||||||
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
|
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
|
||||||
|
import { scramjetPath } from "@mercuryworkshop/scramjet";
|
||||||
import playformCompress from "@playform/compress";
|
import playformCompress from "@playform/compress";
|
||||||
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
|
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
|
||||||
import { scramjetPath } from "@mercuryworkshop/scramjet";
|
|
||||||
import icon from "astro-icon";
|
import icon from "astro-icon";
|
||||||
import { defineConfig, envField } from "astro/config";
|
import { defineConfig, envField } from "astro/config";
|
||||||
import { viteStaticCopy } from "vite-plugin-static-copy";
|
import { viteStaticCopy } from "vite-plugin-static-copy";
|
||||||
import { version } from "./package.json";
|
import { version } from "./package.json";
|
||||||
import { parsedDoc } from "./server/config.js";
|
import { parsedDoc } from "./server/config.js";
|
||||||
|
import { wispPlugin } from "./server/vite-plugin-wisp";
|
||||||
const workerwarePath = fileURLToPath(new URL("./workerware/src", import.meta.url));
|
const workerwarePath = fileURLToPath(new URL("./workerware/src", import.meta.url));
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
site: parsedDoc.seo.enabled ? parsedDoc.seo.domain || process.env.SITE : 'http://localhost:4321',
|
site: parsedDoc.seo.enabled
|
||||||
env: {
|
? parsedDoc.seo.domain || process.env.SITE
|
||||||
schema: {
|
: "http://localhost:4321",
|
||||||
VERSION: envField.string({
|
env: {
|
||||||
context: "client",
|
schema: {
|
||||||
access: "public",
|
VERSION: envField.string({
|
||||||
optional: true,
|
context: "client",
|
||||||
default: version
|
access: "public",
|
||||||
}),
|
optional: true,
|
||||||
MARKETPLACE_ENABLED: envField.boolean({
|
default: version
|
||||||
context: "client",
|
}),
|
||||||
access: "public",
|
MARKETPLACE_ENABLED: envField.boolean({
|
||||||
optional: true,
|
context: "client",
|
||||||
default: parsedDoc.marketplace.enabled
|
access: "public",
|
||||||
}),
|
optional: true,
|
||||||
SEO: envField.string({
|
default: parsedDoc.marketplace.enabled
|
||||||
context: "client",
|
}),
|
||||||
access: "public",
|
SEO: envField.string({
|
||||||
optional: true,
|
context: "client",
|
||||||
default: JSON.stringify({
|
access: "public",
|
||||||
enabled: parsedDoc.seo.enabled,
|
optional: true,
|
||||||
domain: new URL(parsedDoc.seo.domain).host
|
default: JSON.stringify({
|
||||||
})
|
enabled: parsedDoc.seo.enabled,
|
||||||
|
domain: new URL(parsedDoc.seo.domain).host
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
},
|
}
|
||||||
|
},
|
||||||
integrations: [
|
integrations: [
|
||||||
tailwind(),
|
tailwind(),
|
||||||
//sitemap(),
|
//sitemap(),
|
||||||
|
@ -77,7 +80,7 @@ export default defineConfig({
|
||||||
{
|
{
|
||||||
src: `${scramjetPath}/**/*`.replace(/\\/g, "/"),
|
src: `${scramjetPath}/**/*`.replace(/\\/g, "/"),
|
||||||
dest: "scram",
|
dest: "scram",
|
||||||
overwrite: false
|
overwrite: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
src: `${baremuxPath}/**/*`.replace(/\\/g, "/"),
|
src: `${baremuxPath}/**/*`.replace(/\\/g, "/"),
|
||||||
|
@ -90,7 +93,8 @@ export default defineConfig({
|
||||||
overwrite: false
|
overwrite: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}),
|
||||||
|
wispPlugin
|
||||||
],
|
],
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
|
@ -113,12 +117,6 @@ export default defineConfig({
|
||||||
target: "http://localhost:8080",
|
target: "http://localhost:8080",
|
||||||
changeOrigin: true
|
changeOrigin: true
|
||||||
},
|
},
|
||||||
"/wisp/": {
|
|
||||||
target: "ws://localhost:8080/wisp/",
|
|
||||||
changeOrigin: true,
|
|
||||||
ws: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/wisp\//, "")
|
|
||||||
},
|
|
||||||
"/styles": {
|
"/styles": {
|
||||||
target: "http://localhost:8080",
|
target: "http://localhost:8080",
|
||||||
changeOrigin: true
|
changeOrigin: true
|
||||||
|
|
13
package.json
13
package.json
|
@ -32,9 +32,9 @@
|
||||||
"@mercuryworkshop/bare-mux": "^2.1.7",
|
"@mercuryworkshop/bare-mux": "^2.1.7",
|
||||||
"@mercuryworkshop/epoxy-transport": "^2.1.27",
|
"@mercuryworkshop/epoxy-transport": "^2.1.27",
|
||||||
"@mercuryworkshop/libcurl-transport": "^1.3.15",
|
"@mercuryworkshop/libcurl-transport": "^1.3.15",
|
||||||
|
"@mercuryworkshop/scramjet": "https://github.com/MercuryWorkshop/scramjet/releases/download/latest/mercuryworkshop-scramjet-1.0.2-dev.tgz",
|
||||||
"@playform/compress": "^0.1.6",
|
"@playform/compress": "^0.1.6",
|
||||||
"@titaniumnetwork-dev/ultraviolet": "^3.2.10",
|
"@titaniumnetwork-dev/ultraviolet": "^3.2.10",
|
||||||
"@mercuryworkshop/scramjet": "https://github.com/MercuryWorkshop/scramjet/releases/download/latest/mercuryworkshop-scramjet-1.0.2-dev.tgz",
|
|
||||||
"@types/node": "^22.10.2",
|
"@types/node": "^22.10.2",
|
||||||
"@types/sequelize": "^4.28.20",
|
"@types/sequelize": "^4.28.20",
|
||||||
"astro": "^5.1.1",
|
"astro": "^5.1.1",
|
||||||
|
@ -62,5 +62,16 @@
|
||||||
"ora": "^8.1.1",
|
"ora": "^8.1.1",
|
||||||
"sharp": "^0.33.5",
|
"sharp": "^0.33.5",
|
||||||
"tsx": "^4.19.2"
|
"tsx": "^4.19.2"
|
||||||
|
},
|
||||||
|
"packageManager": "pnpm@10.4.1+sha512.c753b6c3ad7afa13af388fa6d808035a008e30ea9993f58c6663e2bc5ff21679aa834db094987129aa4d488b86df57f7b634981b2f827cdcacc698cc0cfb88af",
|
||||||
|
"pnpm": {
|
||||||
|
"onlyBuiltDependencies": [
|
||||||
|
"@biomejs/biome",
|
||||||
|
"bufferutil",
|
||||||
|
"esbuild",
|
||||||
|
"sharp",
|
||||||
|
"sqlite3",
|
||||||
|
"utf-8-validate"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,22 +10,20 @@ import fastifyStatic from "@fastify/static";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import Fastify, { FastifyReply, FastifyRequest } from "fastify";
|
import Fastify, { FastifyReply, FastifyRequest } from "fastify";
|
||||||
import gradient from "gradient-string";
|
import gradient from "gradient-string";
|
||||||
//@ts-ignore WHY would I want this typechecked AT ALL
|
|
||||||
import { handler as ssrHandler } from "../dist/server/entry.mjs";
|
|
||||||
import { parsedDoc } from "./config.js";
|
import { parsedDoc } from "./config.js";
|
||||||
import { setupDB } from "./dbSetup.js";
|
import { setupDB } from "./dbSetup.js";
|
||||||
import { catalogAssets, marketplaceAPI } from "./marketplace.js";
|
import { catalogAssets, marketplaceAPI } from "./marketplace.js";
|
||||||
import { serverFactory } from "./serverFactory.js";
|
import { serverFactory } from "./serverFactory.js";
|
||||||
|
|
||||||
const app = Fastify({
|
const app = Fastify({
|
||||||
logger: parsedDoc.server.server.logging,
|
logger: parsedDoc.server.server.logging,
|
||||||
ignoreDuplicateSlashes: true,
|
ignoreDuplicateSlashes: true,
|
||||||
ignoreTrailingSlash: true,
|
ignoreTrailingSlash: true,
|
||||||
serverFactory: serverFactory
|
serverFactory: serverFactory
|
||||||
});
|
});
|
||||||
|
|
||||||
await app.register(fastifyCompress, {
|
await app.register(fastifyCompress, {
|
||||||
encodings: ["br", "gzip", "deflate"]
|
encodings: ["br", "gzip", "deflate"]
|
||||||
});
|
});
|
||||||
|
|
||||||
await app.register(fastifyMultipart, {
|
await app.register(fastifyMultipart, {
|
||||||
|
@ -36,58 +34,60 @@ await app.register(fastifyMultipart, {
|
||||||
});
|
});
|
||||||
|
|
||||||
await app.register(fastifyHelmet, {
|
await app.register(fastifyHelmet, {
|
||||||
xPoweredBy: false,
|
xPoweredBy: false,
|
||||||
crossOriginEmbedderPolicy: true,
|
crossOriginEmbedderPolicy: true,
|
||||||
crossOriginOpenerPolicy: true,
|
crossOriginOpenerPolicy: true,
|
||||||
contentSecurityPolicy: false //Disabled because astro DOES NOT LIKE IT
|
contentSecurityPolicy: false //Disabled because astro DOES NOT LIKE IT
|
||||||
});
|
});
|
||||||
|
|
||||||
await app.register(fastifyStatic, {
|
await app.register(fastifyStatic, {
|
||||||
root: fileURLToPath(new URL("../dist/client", import.meta.url))
|
root: fileURLToPath(new URL("../dist/client", import.meta.url))
|
||||||
});
|
});
|
||||||
|
|
||||||
//Our marketplace API. Not middleware as I don't want to deal with that LOL. Just a function that passes our app to it.
|
//Our marketplace API. Not middleware as I don't want to deal with that LOL. Just a function that passes our app to it.
|
||||||
if (parsedDoc.marketplace.enabled) {
|
if (parsedDoc.marketplace.enabled) {
|
||||||
await app.register(fastifyStatic, {
|
await app.register(fastifyStatic, {
|
||||||
root: fileURLToPath(new URL("../database_assets", import.meta.url)),
|
root: fileURLToPath(new URL("../database_assets", import.meta.url)),
|
||||||
prefix: "/packages/",
|
prefix: "/packages/",
|
||||||
decorateReply: false
|
decorateReply: false
|
||||||
});
|
});
|
||||||
marketplaceAPI(app);
|
marketplaceAPI(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
await app.register(fastifyMiddie);
|
await app.register(fastifyMiddie);
|
||||||
|
if (process.env.NODE_ENV === "production") {
|
||||||
app.use(ssrHandler);
|
//@ts-ignore WHY would I want this typechecked AT ALL
|
||||||
|
const { handler: ssrHandler } = await import("../dist/server/entry.mjs")
|
||||||
|
app.use(ssrHandler);
|
||||||
|
}
|
||||||
const port: number =
|
const port: number =
|
||||||
parseInt(process.env.PORT as string) || parsedDoc.server.server.port || parseInt("8080");
|
parseInt(process.env.PORT as string) || parsedDoc.server.server.port || parseInt("8080");
|
||||||
const titleText = `
|
const titleText = `
|
||||||
_ _ _ _ ____ _
|
_ _ _ _ ____ _
|
||||||
| \\ | | ___| |__ _ _| | __ _ / ___| ___ _ ____ _(_) ___ ___ ___
|
| \\ | | ___| |__ _ _| | __ _ / ___| ___ _ ____ _(_) ___ ___ ___
|
||||||
| \\| |/ _ \\ '_ \\| | | | |/ _' | \\___ \\ / _ \\ '__\\ \\ / / |/ __/ _ \\/ __|
|
| \\| |/ _ \\ '_ \\| | | | |/ _' | \\___ \\ / _ \\ '__\\ \\ / / |/ __/ _ \\/ __|
|
||||||
| |\\ | __/ |_) | |_| | | (_| | ___) | __/ | \\ V /| | (_| __/\\__ \\
|
| |\\ | __/ |_) | |_| | | (_| | ___) | __/ | \\ V /| | (_| __/\\__ \\
|
||||||
|_| \\_|\\___|_.__/ \\__,_|_|\\__,_| |____/ \\___|_| \\_/ |_|\\___\\___||___/
|
|_| \\_|\\___|_.__/ \\__,_|_|\\__,_| |____/ \\___|_| \\_/ |_|\\___\\___||___/
|
||||||
`;
|
`;
|
||||||
const titleColors = {
|
const titleColors = {
|
||||||
purple: "#7967dd",
|
purple: "#7967dd",
|
||||||
pink: "#eb6f92"
|
pink: "#eb6f92"
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(gradient(Object.values(titleColors)).multiline(titleText as string));
|
console.log(gradient(Object.values(titleColors)).multiline(titleText as string));
|
||||||
app.listen({ port: port, host: "0.0.0.0" }).then(async () => {
|
app.listen({ port: port, host: "0.0.0.0" }).then(async () => {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.hex("#7967dd")(
|
chalk.hex("#7967dd")(
|
||||||
`Server listening on ${chalk.hex("#eb6f92").bold("http://localhost:" + port + "/")}`
|
`Server listening on ${chalk.hex("#eb6f92").bold("http://localhost:" + port + "/")}`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
console.log(
|
console.log(
|
||||||
chalk.hex("#7967dd")(
|
chalk.hex("#7967dd")(
|
||||||
`Server also listening on ${chalk.hex("#eb6f92").bold("http://0.0.0.0:" + port + "/")}`
|
`Server also listening on ${chalk.hex("#eb6f92").bold("http://0.0.0.0:" + port + "/")}`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (parsedDoc.marketplace.enabled) {
|
if (parsedDoc.marketplace.enabled) {
|
||||||
await catalogAssets.sync();
|
await catalogAssets.sync();
|
||||||
await setupDB(catalogAssets);
|
await setupDB(catalogAssets);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,4 +26,4 @@ const serverFactory: FastifyServerFactory = (
|
||||||
return httpServer;
|
return httpServer;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { serverFactory };
|
export { serverFactory, wispOptions };
|
||||||
|
|
15
server/vite-plugin-wisp.ts
Normal file
15
server/vite-plugin-wisp.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { Socket } from "node:net";
|
||||||
|
import wisp from "wisp-server-node";
|
||||||
|
import { wispOptions } from "./serverFactory";
|
||||||
|
|
||||||
|
export const wispPlugin = {
|
||||||
|
name: "vite-plugin-wisp",
|
||||||
|
configureServer(server) {
|
||||||
|
server.wisp = wisp;
|
||||||
|
server.httpServer?.on("upgrade", (req, socket: Socket, head) =>
|
||||||
|
req.url?.endsWith("/wisp/")
|
||||||
|
? wisp.routeRequest(req, socket, head, wispOptions)
|
||||||
|
: undefined
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue