env vars
This commit is contained in:
parent
b0229c0817
commit
e812c78d52
9 changed files with 59 additions and 11 deletions
|
@ -17,6 +17,8 @@ for conditions such as dementia. Over time, the idea evolved and is now a genera
|
|||
|
||||
The Identity project is composed by a web-app and two servers. In the future, Docker containers may be built to ease the installation of this project.
|
||||
|
||||
The recommended Node.JS version is v21.5.0, others should also work.
|
||||
|
||||
### Development and local testing
|
||||
|
||||
#### `identity-web`
|
||||
|
|
2
asset-api/.env.example
Normal file
2
asset-api/.env.example
Normal file
|
@ -0,0 +1,2 @@
|
|||
ASSET_API_ASSETS_FOLDER = "./.assets/"
|
||||
ASSET_API_IDENTITY_API_ENDPOINT = "http://localhost:3000/"
|
2
asset-api/.gitignore
vendored
2
asset-api/.gitignore
vendored
|
@ -14,3 +14,5 @@
|
|||
|
||||
.keys
|
||||
.assets
|
||||
|
||||
.env
|
|
@ -1,18 +1,19 @@
|
|||
{
|
||||
"name": "asset-api",
|
||||
"main": "index.js",
|
||||
"main": "src/index.js",
|
||||
"type": "module",
|
||||
"license": "AGPL-3.0-only",
|
||||
"packageManager": "yarn@4.3.0",
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^9.0.1",
|
||||
"@fastify/multipart": "^8.3.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"fastify": "^4.28.0",
|
||||
"mime": "^4.0.3",
|
||||
"uuid": "^10.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"start": "node src/index.js",
|
||||
"lint:fix": "eslint --fix && prettier . --write",
|
||||
"lint": "eslint && prettier . --check"
|
||||
},
|
||||
|
|
38
asset-api/src/consts.js
Normal file
38
asset-api/src/consts.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Identity. Store your memories and mental belongings
|
||||
// Copyright (C) 2024 Sofía Aritz
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published
|
||||
// by the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import "dotenv/config";
|
||||
|
||||
const REQUIRED_VARS = [
|
||||
"ASSET_API_ASSETS_FOLDER",
|
||||
"ASSET_API_IDENTITY_API_ENDPOINT"
|
||||
];
|
||||
|
||||
REQUIRED_VARS.forEach((element) => {
|
||||
if (
|
||||
process.env[element] == null ||
|
||||
(typeof process.env[element] === "string" && process.env[element].length === 0)
|
||||
) {
|
||||
console.error(`Required environment variable was not set: ${element}`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
export const ASSET_API_LANDING_MESSAGE = process.env["ASSET_API_LANDING_MESSAGE"] || "asset-api v0.0.1";
|
||||
export const LISTEN_PORT = Number(process.env["ASSET_API_LISTEN_PORT"]) || 3001;
|
||||
export const ASSETS_FOLDER = process.env["ASSET_API_ASSETS_FOLDER"];
|
||||
export const IDENTITY_API_ENDPOINT = process.env["ASSET_API_IDENTITY_API_ENDPOINT"];
|
||||
export const M2M_ALGORITHM = process.env["ASSET_API_M2M_ALGORITHM"] || "RSA-SHA512";
|
|
@ -24,19 +24,14 @@ import mime from "mime";
|
|||
import { promisify } from "node:util";
|
||||
import { pipeline } from "node:stream";
|
||||
import cors from "@fastify/cors";
|
||||
import { M2M_ALGORITHM, ASSETS_FOLDER, ASSET_API_LANDING_MESSAGE, IDENTITY_API_ENDPOINT } from "./consts.js";
|
||||
|
||||
const M2M_ALGORITHM = "RSA-SHA512";
|
||||
const { private: M2M_PRIVATE_KEY, public: M2M_PUBLIC_KEY } = loadM2MKeys();
|
||||
if (M2M_PRIVATE_KEY == null || M2M_PUBLIC_KEY == null) {
|
||||
console.error("Couldn't load keys");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const ASSETS_FOLDER = "./.assets/";
|
||||
const ASSET_API_LANDING_MESSAGE = "asset-api v1.0.0";
|
||||
|
||||
const IDENTITY_API_ENDPOINT = "http://localhost:3000";
|
||||
|
||||
const app = new Fastify({
|
||||
logger: true,
|
||||
});
|
|
@ -296,6 +296,7 @@ __metadata:
|
|||
"@eslint/js": "npm:^9.5.0"
|
||||
"@fastify/cors": "npm:^9.0.1"
|
||||
"@fastify/multipart": "npm:^8.3.0"
|
||||
dotenv: "npm:^16.4.5"
|
||||
eslint: "npm:9.x"
|
||||
fastify: "npm:^4.28.0"
|
||||
globals: "npm:^15.5.0"
|
||||
|
@ -433,6 +434,13 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"dotenv@npm:^16.4.5":
|
||||
version: 16.4.5
|
||||
resolution: "dotenv@npm:16.4.5"
|
||||
checksum: 10c0/48d92870076832af0418b13acd6e5a5a3e83bb00df690d9812e94b24aff62b88ade955ac99a05501305b8dc8f1b0ee7638b18493deb6fe93d680e5220936292f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"escape-string-regexp@npm:^4.0.0":
|
||||
version: 4.0.0
|
||||
resolution: "escape-string-regexp@npm:4.0.0"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
IDENTITY_API_LANDING_MESSAGE = "identity-api v1.0.0"
|
||||
IDENTITY_API_LANDING_MESSAGE = "identity-api v0.0.1"
|
||||
IDENTITY_API_JWT_SECRET = "cc7e0d44fd473002f1c42167459001140ec6389b7353f8088f4d9a95f2f596f2"
|
||||
IDENTITY_API_JWT_ALG = "HS256"
|
||||
IDENTITY_API_ASSET_API_ENDPOINT = "http://localhost:3001"
|
||||
|
|
|
@ -34,7 +34,7 @@ REQUIRED_VARS.forEach((element) => {
|
|||
}
|
||||
});
|
||||
|
||||
export const IDENTITY_API_LANDING_MESSAGE = process.env["IDENTITY_API_LANDING_MESSAGE"] || "identity-api v1.0.0";
|
||||
export const IDENTITY_API_LANDING_MESSAGE = process.env["IDENTITY_API_LANDING_MESSAGE"] || "identity-api v0.0.1";
|
||||
export const JWT_SECRET = new TextEncoder().encode(process.env["IDENTITY_API_JWT_SECRET"]);
|
||||
export const JWT_ALG = process.env["IDENTITY_API_JWT_ALG"];
|
||||
export const LISTEN_PORT = Number(process.env["IDENTITY_API_LISTEN_PORT"]) || 3000;
|
||||
|
|
Loading…
Reference in a new issue