Update src/server/main.ts
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e8f0516ccb
commit
7fdd467c8c
35
server.js
35
server.js
@ -1,35 +0,0 @@
|
|||||||
const fastify = require("fastify")(); //{ logger: true });
|
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
fastify.register(require("@fastify/static"), {
|
|
||||||
root: path.join(__dirname, "public"),
|
|
||||||
prefix: "/public/",
|
|
||||||
});
|
|
||||||
|
|
||||||
fastify.register(
|
|
||||||
require("@fastify/leveldb"),
|
|
||||||
{
|
|
||||||
name: "db",
|
|
||||||
},
|
|
||||||
(err) => {
|
|
||||||
if (err) throw err;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
fastify.register(require("@fastify/view"), {
|
|
||||||
engine: {
|
|
||||||
pug: require("pug"),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
fastify.register(require("./router/api"), { prefix: "/api" });
|
|
||||||
|
|
||||||
fastify.get("/", (req, reply) => reply.view("/template/home.pug"));
|
|
||||||
fastify.get("/:id", (req, reply) => reply.view("/template/journey.pug"));
|
|
||||||
fastify.get("/view/:id", (req, reply) => reply.view("/template/view.pug"));
|
|
||||||
fastify.get("/short/:id", (req, reply) => reply.view("/template/short.pug"));
|
|
||||||
|
|
||||||
fastify.listen({ port: 8080, host: "0.0.0.0" }, (err, address) => {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log("Listening on", address);
|
|
||||||
});
|
|
36
src/server/main.ts
Normal file
36
src/server/main.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import fastify from 'fastify'
|
||||||
|
import fastify_static from '@fastify/static'
|
||||||
|
import fastify_db from '@fastify/leveldb'
|
||||||
|
import fastify_view from '@fastify/view';
|
||||||
|
import pug from 'pug'
|
||||||
|
import { join as pathJoin } from "path";
|
||||||
|
|
||||||
|
import api from "./router/api"
|
||||||
|
|
||||||
|
const server = fastify(); //{ logger: true });
|
||||||
|
|
||||||
|
server.register(fastify_static, {
|
||||||
|
root: pathJoin(__dirname, "public"),
|
||||||
|
prefix: "/public/",
|
||||||
|
});
|
||||||
|
|
||||||
|
server.register(
|
||||||
|
fastify_db as any,
|
||||||
|
{ name: "db" }
|
||||||
|
);
|
||||||
|
|
||||||
|
server.register(fastify_view, {
|
||||||
|
engine: { pug: pug },
|
||||||
|
});
|
||||||
|
|
||||||
|
server.register(api, { prefix: "/api" });
|
||||||
|
|
||||||
|
server.get("/", (req, reply) => reply.view("/template/home.pug"));
|
||||||
|
server.get("/:id", (req, reply) => reply.view("/template/journey.pug"));
|
||||||
|
server.get("/view/:id", (req, reply) => reply.view("/template/view.pug"));
|
||||||
|
server.get("/short/:id", (req, reply) => reply.view("/template/short.pug"));
|
||||||
|
|
||||||
|
server.listen({ port: 8080, host: "0.0.0.0" }, (err, address) => {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log("Listening on", address);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user