Эх сурвалжийг харах

update fastify from v3 to v4 (#7965)

* update fastify from v3 to v4

* fix: updated for @fasity/view v7.4.1
Dan Castillo 2 жил өмнө
parent
commit
98441d39e7

+ 5 - 6
frameworks/JavaScript/fastify/create-server.js

@@ -1,11 +1,10 @@
 const fastify = require("fastify")();
 const handlers = require("./handlers");
 
-fastify.register(require("point-of-view"), {
+fastify.register(require("@fastify/view"), {
   engine: {
-    ejs: require("handlebars")
-  },
-  templates: __dirname + "/views"
+    handlebars: require("handlebars")
+  }
 });
 
 fastify.addHook('onRequest', (request, reply, done) => {
@@ -94,12 +93,12 @@ if (database) {
   fastify.get("/updates", updateSchema, routerHandler.updates);
 }
 
-fastify.listen(8080, "0.0.0.0", err => {
+fastify.listen({ port: 8080, host: "0.0.0.0" }, (err, address) => {
   if (err) {
     throw err;
   }
 
   console.log(
-    `Worker started and listening on http://0.0.0.0:8080 ${new Date().toISOString()}`
+    `Worker started and listening on ${address} ${new Date().toISOString()}`
   );
 });

+ 7 - 4
frameworks/JavaScript/fastify/db/mongo.js

@@ -1,4 +1,4 @@
-const MongoClient = require("mongodb").MongoClient;
+const { MongoClient } = require("mongodb");
 
 const mongoUrl = "mongodb://tfb-database:27017";
 const dbName = "hello_world";
@@ -7,10 +7,13 @@ let client;
 
 async function getCollection(name) {
   if (!client) {
-    client = await MongoClient.connect(
+    client = await new MongoClient(
       mongoUrl,
-      { useNewUrlParser: true }
-    );
+      {
+        useNewUrlParser: true,
+        useUnifiedTopology: true
+      }
+    ).connect();
   }
 
   const db = client.db(dbName);

+ 1 - 1
frameworks/JavaScript/fastify/handlers.js

@@ -30,7 +30,7 @@ module.exports = databaseLayer => ({
     fortunes.push(h.additionalFortune);
     fortunes.sort(compare);
 
-    reply.view("fortunes.hbs", { fortunes });
+    return reply.view("/views/fortunes.hbs", { fortunes });
   },
 
   updates: async (req, reply) => {

+ 4 - 4
frameworks/JavaScript/fastify/package.json

@@ -5,12 +5,12 @@
   "main": "app.js",
   "private": true,
   "dependencies": {
-    "fastify": "3.27.4",
+    "@fastify/view": "7.4.1",
+    "fastify": "4.13.0",
     "handlebars": "4.7.6",
-    "knex": "0.21.17",
+    "knex": "2.4.2",
     "mongodb": "3.5.9",
     "mysql2": "2.2.5",
-    "pg": "8.5.1",
-    "point-of-view": "4.2.0"
+    "pg": "8.5.1"
   }
 }