feat: working sample webserver

This commit is contained in:
Derock 2023-09-17 12:09:56 -04:00
parent 3f73f48d00
commit 1b639f5433
No known key found for this signature in database
5 changed files with 36 additions and 10 deletions

View file

@ -3,16 +3,17 @@
"version": "1.0.50",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "bun run --watch src/index.ts"
"dev": "bun --watch src/index.ts"
},
"dependencies": {
"@elysiajs/cookie": "^0.6.1",
"@elysiajs/swagger": "^0.6.2",
"@t3-oss/env-core": "^0.6.1",
"elysia": "^0.6.23",
"elysia": "latest",
"zod": "^3.22.2"
},
"devDependencies": {
"bun-types": "latest"
},
"module": "src/index.js"
}
}

View file

@ -1,3 +1,9 @@
import Elysia from "elysia";
import { Elysia } from "elysia";
import type { BaseElysiaContext } from "../..";
export const authController = new Elysia({ prefix: "/auth" });
export const authController = new Elysia<"/auth", BaseElysiaContext>({
prefix: "/auth",
}).get("/cookie", (...args) => {
console.log(args);
return "cookie";
});

View file

@ -6,7 +6,7 @@ export const env = createEnv({
* Serverside environment variables
*/
server: {
port: z.number(),
port: z.preprocess(Number, z.number()),
host: z.string(),
},

View file

@ -1,7 +1,26 @@
import { Elysia } from "elysia";
import { ElysiaLoader } from "./loader";
import { cookie } from "@elysiajs/cookie";
import { authController } from "./controllers/auth";
import { env } from "./env";
// const app = new ElysiaLoader(new Elysia()).load(import("./controllers/auth"));
let app = new Elysia();
app = app.use(authController);
// base elysia app with all the plugins
const baseApp = new Elysia().use(cookie());
type ExtractContext<T> = T extends Elysia<infer _U, infer V> ? V : never;
export type BaseElysiaContext = ExtractContext<typeof baseApp>;
// add in our routes
const withRoutes = baseApp.use(authController);
export type ElysiaWithRoutes = typeof withRoutes;
// if this is the main module, start the server
if (import.meta.main) {
withRoutes.listen(
{
port: env.port,
hostname: env.host,
},
(data) => {
console.log(`🚀 listening on ${data.hostname}:${data.port}`);
}
);
}

BIN
bun.lockb Normal file → Executable file

Binary file not shown.