diff --git a/lib/response.js b/lib/response.js index a982f3d4..72525f18 100644 --- a/lib/response.js +++ b/lib/response.js @@ -6,7 +6,7 @@ export function json(res, data = {}) { return res.status(200).json(data); } -export function send(res, data, type = 'text-plain') { +export function send(res, data, type = 'text/plain') { res.setHeader('Content-Type', type); return res.status(200).send(data); diff --git a/package.json b/package.json index 74b95081..7b6b2ec9 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "scripts": { "dev": "next dev", "build": "npm-run-all build-tracker build-geo build-db build-app", - "start": "npm-run-all telemetry start-app", + "start": "npm-run-all init start-app", "start-app": "next start", "start-env": "node -r dotenv/config scripts/start-env.js", "build-app": "next build", @@ -26,7 +26,6 @@ "build-mysql-client": "dotenv prisma generate -- --schema=./prisma/schema.mysql.prisma", "build-postgresql-schema": "dotenv prisma db pull -- --schema=./prisma/schema.postgresql.prisma", "build-postgresql-client": "dotenv prisma generate -- --schema=./prisma/schema.postgresql.prisma", - "init": "node scripts/init.js", "copy-db-schema": "node scripts/copy-db-schema.js", "generate-lang": "npm-run-all extract-lang merge-lang", "extract-lang": "formatjs extract \"{pages,components}/**/*.js\" --out-file build/messages.json", @@ -37,9 +36,10 @@ "download-country-names": "node scripts/download-country-names.js", "download-language-names": "node scripts/download-language-names.js", "change-password": "node scripts/change-password.js", - "telemetry": "node scripts/telemetry.js", "lint": "next lint --quiet", - "prepare": "husky install" + "prepare": "husky install", + "postbuild": "node scripts/postbuild.js", + "init": "node scripts/prestart.js" }, "lint-staged": { "**/*.js": [ diff --git a/scripts/postbuild.js b/scripts/postbuild.js new file mode 100644 index 00000000..55414dcf --- /dev/null +++ b/scripts/postbuild.js @@ -0,0 +1,10 @@ +require('dotenv').config(); +const { sendTelemetry } = require('./telemetry'); + +async function run() { + if (!process.env.DISABLE_TELEMETRY) { + await sendTelemetry(); + } +} + +run(); diff --git a/scripts/prestart.js b/scripts/prestart.js new file mode 100644 index 00000000..55414dcf --- /dev/null +++ b/scripts/prestart.js @@ -0,0 +1,10 @@ +require('dotenv').config(); +const { sendTelemetry } = require('./telemetry'); + +async function run() { + if (!process.env.DISABLE_TELEMETRY) { + await sendTelemetry(); + } +} + +run(); diff --git a/scripts/telemetry.js b/scripts/telemetry.js index 3714ff35..6dbc586e 100644 --- a/scripts/telemetry.js +++ b/scripts/telemetry.js @@ -1,4 +1,3 @@ -require('dotenv').config(); const fs = require('fs-extra'); const path = require('path'); const os = require('os'); @@ -53,10 +52,6 @@ async function sendTelemetry() { } } -async function run() { - if (!process.env.DISABLE_TELEMETRY) { - await sendTelemetry(); - } -} - -run(); +module.exports = { + sendTelemetry, +};