Skip to content

Instantly share code, notes, and snippets.

@matt212
Created July 30, 2022 08:22
Show Gist options
  • Save matt212/e89f2b2418ad47a568321db7bea1c0f4 to your computer and use it in GitHub Desktop.
Save matt212/e89f2b2418ad47a568321db7bea1c0f4 to your computer and use it in GitHub Desktop.
//const pinoInspector = require("pino-inspector");
const path = require("path");
const fastify = require("fastify")({
//logger: { prettyPrint: true, level: "debug", prettifier: pinoInspector },
ajv: {
plugins: [[require("ajv-keywords"), ["transform"]]],
},
});
fastify.register(require("@fastify/multipart"));
fastify.register(
require("fastify-compress"),
{ global: false },
{ encodings: ["gzip"] }
);
if (process.argv[2] == "dev") {
fastify.register(require("fastify-static"), {
root: path.join(__dirname, "../") + "/public",
// prefix:'/public',
});
} else if (process.argv[2] == "prod") {
fastify.register(require("fastify-static"), {
root: path.join(__dirname, "../") + "/public-release",
// prefix:'/public',
});
}
else {
fastify.register(require("fastify-static"), {
root: path.join(__dirname, "../") + "/public",
// prefix:'/public',
});
}
fastify.register(require("point-of-view"), {
engine: {
ejs: require("ejs"),
},
root: path.join(__dirname, "../views"),
});
fastify.register(require("fastify-cors"));
fastify.register(require("fastify-jwt"), {
secret: "supersecret",
expiresIn: "1h",
});
fastify.register(require("fastify-secure-session"), {
secret: "averylogphrasebiggerthanfortytwochars",
salt: "mq9hDxBVDbspDR6n",
cookie: {
path: "/",
// options for setCookie, see https://github.com/fastify/fastify-cookie
},
});
fastify.addHook('preHandler', (request, reply, next) => {
if (process.argv[2] == "dev") {
request.session.releaseEnv = "public";
} else {
request.session.releaseEnv = "public-release";
}
next();
})
fastify.register(require("../../app/config/baseAuth"));
fastify.register(require("../routes/customauth"), { prefix: "/" });
fastify.register(require("../routes/utils/misc/jynerso"), {
prefix: "/black-squadron",
});
let baseroutes = require("../config/baseRoute");
baseroutes.forEach(function (dt) {
fastify.register(require(`../routes/${dt.val}`), { prefix: dt.key });
});
// Run the server!
fastify.listen(3011, function (err, address) {
if (err) {
fastify.log.error(err);
process.exit(1);
}
console.log(`App Server listening on port ${address}`);
});
fastify.register(require("fastify-socket.io"), {
// put your options here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment