Skip to content

Commit

Permalink
migrate json scret
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Jan 5, 2025
1 parent ae5a288 commit b594433
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 18 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NUXT_PUBLIC_SECRET_FILE=.secret.json
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ logs
.fleet
.idea

# Local env files
.env
.env.*
!.env.example

# Secret file from Dexus
libs/deepnest_dxf2svg-processor

.secret.json
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,25 @@ Locally preview production build:
npm run preview
```

## Secrets

Project use docker secrets for storing sensitive data. For local development create `.secret.json` file in the root of the project.
In case you want to getting secret from other file change the `.env` file.

Sample of `.secret.json` file:

```json
{
"mongoUri": "mongodb://<user>:<pass>@<ip>:<port>/<dbname>?<connection specific options>"
}
```

### Referenced Paper

- [López-Camacho _et al._ 2013](http://www.cs.stir.ac.uk/~goc/papers/EffectiveHueristic2DAOR2013.pdf)
- [Kendall 2000](http://www.graham-kendall.com/papers/k2001.pdf)
- [E.K. Burke _et al._ 2006](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.440.379&rep=rep1&type=pdf)

```
```
4 changes: 3 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export default defineNuxtConfig({
devtools: { enabled: true },
modules: ["@nuxtjs/tailwindcss"],
runtimeConfig: {
dbUrl: "",
public: {
secretFile: ".secret.json",
},
},
});
2 changes: 1 addition & 1 deletion server/api/project.post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineEventHandler, createError, readMultipartFormData } from "h3";
import { connectDB } from "~~/server/db/mongo";
import { getDxfArray } from "~~/server/utils/multipart";
import { generateSvg } from "../core/svg/generator";
import { generateRandomString } from "../utils";
import { generateRandomString } from "~~/server/utils/strings";
import { dxf2Json } from "~~/libs/deepnest_dxf2svg-processor";

export default defineEventHandler(async (event) => {
Expand Down
16 changes: 12 additions & 4 deletions server/api/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import { connectDB } from "~~/server/db/mongo";
export default defineEventHandler(async (_) => {
const db = await connectDB();

db.collection("uploads").insertOne({ name: "test1" });
let isDbConnected = false;

const response = {};
response.version = "0.6.0";
return response;
try {
await db.command({ ping: 1 });
isDbConnected = true;
} catch (e) {
console.error(e);
}

return {
isDbConnected: isDbConnected,
version: "0.1.0",
};
});
2 changes: 0 additions & 2 deletions server/core/dxf/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export function parseAndCombine(dxfObject, tolerance) {

const allProcessed = dxfEntities.map((ent) => {
const points = entityToPoints(ent, tolerance);
// print points
console.log(points);
const isClosed =
isInherentlyClosed(ent) || isClosedPolygon(points, tolerance);
return {
Expand Down
4 changes: 2 additions & 2 deletions server/db/mongo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MongoClient } from "mongodb";
import { getConfig } from "../utils/config";

const runtimeConfig = useRuntimeConfig();
const uri = runtimeConfig.dbUrl;
const uri = getConfig().mongoUri;

let client;
/**
Expand Down
7 changes: 4 additions & 3 deletions server/scheduler/pulse.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Pulse } from "@pulsecron/pulse";

const runtimeConfig = useRuntimeConfig();
const mongoUrl = runtimeConfig.dbUrl;
import { getConfig } from "../utils/config";

const uri = getConfig().mongoUri;

const pulse = new Pulse({
db: { address: mongoUrl, collection: "pulse_jobs" },
db: { address: uri, collection: "pulse_jobs" },
resumeOnRestart: true,
});

Expand Down
7 changes: 7 additions & 0 deletions server/utils/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fs from "fs";
const runtimeConfig = useRuntimeConfig().public;

export function getConfig() {
const asText = fs.readFileSync(runtimeConfig.secretFile, "utf8");
return JSON.parse(asText);
}
File renamed without changes.

0 comments on commit b594433

Please sign in to comment.