mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
prettier
This commit is contained in:
parent
4b0337db0c
commit
55b6666229
43 changed files with 4693 additions and 2712 deletions
164
server.js
164
server.js
|
@ -1,80 +1,84 @@
|
|||
// Dev server imports
|
||||
import { createBareServer } from "@tomphttp/bare-server-node";
|
||||
import { createServer } from "http";
|
||||
import Fastify from "fastify";
|
||||
import fastifyStatic from "@fastify/static";
|
||||
import { join } from "node:path";
|
||||
import { spawn } from "node:child_process"
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
//transports
|
||||
import { baremuxPath } from "@mercuryworkshop/bare-mux/node"
|
||||
import { epoxyPath } from "@mercuryworkshop/epoxy-transport"
|
||||
import { libcurlPath } from "@mercuryworkshop/libcurl-transport"
|
||||
import { bareModulePath } from "@mercuryworkshop/bare-as-module3"
|
||||
|
||||
const bare = createBareServer("/bare/", {
|
||||
logErrors: true
|
||||
});
|
||||
|
||||
const fastify = Fastify({
|
||||
serverFactory: (handler) => {
|
||||
return createServer()
|
||||
.on("request", (req, res) => {
|
||||
if (bare.shouldRoute(req)) {
|
||||
bare.routeRequest(req, res);
|
||||
} else {
|
||||
handler(req, res);
|
||||
}
|
||||
}).on("upgrade", (req, socket, head) => {
|
||||
if (bare.shouldRoute(req)) {
|
||||
bare.routeUpgrade(req, socket, head);
|
||||
} else {
|
||||
socket.end();
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
fastify.register(fastifyStatic, {
|
||||
root: join(fileURLToPath(new URL(".", import.meta.url)), "./static"),
|
||||
decorateReply: false
|
||||
});
|
||||
fastify.register(fastifyStatic, {
|
||||
root: join(fileURLToPath(new URL(".", import.meta.url)), "./dist"),
|
||||
prefix: "/scram/",
|
||||
decorateReply: false
|
||||
})
|
||||
fastify.register(fastifyStatic, {
|
||||
root: baremuxPath,
|
||||
prefix: "/baremux/",
|
||||
decorateReply: false
|
||||
})
|
||||
fastify.register(fastifyStatic, {
|
||||
root: epoxyPath,
|
||||
prefix: "/epoxy/",
|
||||
decorateReply: false
|
||||
})
|
||||
fastify.register(fastifyStatic, {
|
||||
root: libcurlPath,
|
||||
prefix: "/libcurl/",
|
||||
decorateReply: false
|
||||
})
|
||||
fastify.register(fastifyStatic, {
|
||||
root: bareModulePath,
|
||||
prefix: "/baremod/",
|
||||
decorateReply: false
|
||||
})
|
||||
fastify.listen({
|
||||
port: process.env.PORT || 1337
|
||||
});
|
||||
|
||||
const watch = spawn("pnpm", ["rspack", "-w"], { detached: true, cwd: process.cwd() });
|
||||
|
||||
watch.stdout.on("data", (data) => {
|
||||
console.log(`${data}`);
|
||||
});
|
||||
|
||||
watch.stderr.on("data", (data) => {
|
||||
console.log(`${data}`);
|
||||
});
|
||||
// Dev server imports
|
||||
import { createBareServer } from "@tomphttp/bare-server-node";
|
||||
import { createServer } from "http";
|
||||
import Fastify from "fastify";
|
||||
import fastifyStatic from "@fastify/static";
|
||||
import { join } from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
//transports
|
||||
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
|
||||
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
|
||||
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
|
||||
import { bareModulePath } from "@mercuryworkshop/bare-as-module3";
|
||||
|
||||
const bare = createBareServer("/bare/", {
|
||||
logErrors: true,
|
||||
});
|
||||
|
||||
const fastify = Fastify({
|
||||
serverFactory: (handler) => {
|
||||
return createServer()
|
||||
.on("request", (req, res) => {
|
||||
if (bare.shouldRoute(req)) {
|
||||
bare.routeRequest(req, res);
|
||||
} else {
|
||||
handler(req, res);
|
||||
}
|
||||
})
|
||||
.on("upgrade", (req, socket, head) => {
|
||||
if (bare.shouldRoute(req)) {
|
||||
bare.routeUpgrade(req, socket, head);
|
||||
} else {
|
||||
socket.end();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
fastify.register(fastifyStatic, {
|
||||
root: join(fileURLToPath(new URL(".", import.meta.url)), "./static"),
|
||||
decorateReply: false,
|
||||
});
|
||||
fastify.register(fastifyStatic, {
|
||||
root: join(fileURLToPath(new URL(".", import.meta.url)), "./dist"),
|
||||
prefix: "/scram/",
|
||||
decorateReply: false,
|
||||
});
|
||||
fastify.register(fastifyStatic, {
|
||||
root: baremuxPath,
|
||||
prefix: "/baremux/",
|
||||
decorateReply: false,
|
||||
});
|
||||
fastify.register(fastifyStatic, {
|
||||
root: epoxyPath,
|
||||
prefix: "/epoxy/",
|
||||
decorateReply: false,
|
||||
});
|
||||
fastify.register(fastifyStatic, {
|
||||
root: libcurlPath,
|
||||
prefix: "/libcurl/",
|
||||
decorateReply: false,
|
||||
});
|
||||
fastify.register(fastifyStatic, {
|
||||
root: bareModulePath,
|
||||
prefix: "/baremod/",
|
||||
decorateReply: false,
|
||||
});
|
||||
fastify.listen({
|
||||
port: process.env.PORT || 1337,
|
||||
});
|
||||
|
||||
const watch = spawn("pnpm", ["rspack", "-w"], {
|
||||
detached: true,
|
||||
cwd: process.cwd(),
|
||||
});
|
||||
|
||||
watch.stdout.on("data", (data) => {
|
||||
console.log(`${data}`);
|
||||
});
|
||||
|
||||
watch.stderr.on("data", (data) => {
|
||||
console.log(`${data}`);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue