Fixed manual setup (alongside docker)

This commit is contained in:
Daniel 2022-06-21 20:23:17 +04:30
parent ace0135a11
commit ed0ab482a7
9 changed files with 38 additions and 44 deletions

View File

@ -4,5 +4,4 @@ api
.dockerignore .dockerignore
Dockerfile* Dockerfile*
node_modules node_modules
media/** api/media
!media/explanation

3
.gitignore vendored
View File

@ -12,8 +12,7 @@ npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
media/** api/media
!media/explanation
api/.ash_history api/.ash_history
api/.config api/.config
api/.cache/ api/.cache/

View File

@ -42,20 +42,21 @@ The objective is to have a self-hosted place to keep useful links in one place,
2. Clone this repository. 2. Clone this repository.
4. [Optional] If you want to use this app across the network change `REACT_APP_API_HOST` in docker-compose.yml with the computer IP and port. 4. [Optional] If you want to use this app across the network change `REACT_APP_API_HOST` in docker-compose.yml with the computer IP and API port.
3. head to the main folder and run `docker compose up`. 3. head to the main folder and run `docker compose up`.
### Manual Setup ### Manual Setup
(Unstable for now.)
1. Make sure your MongoDB database and collection is up and running. 1. Make sure your MongoDB database and collection is up and running.
2. Edit [/src/config.js](src/config.js) accordingly. 2. Edit [URI, Database name and Collection name](api/config.js) accordingly.
3. Head to the main folder using terminal and run: `(cd api && npm install) && npm install --legacy-peer-deps` for the dependencies. 3. [Optional] If you want to use this app across the network change [`API_HOST`](src/config.js) address with the computer IP and API port.
4. Run `npm start` to start the application. 4. Head to the main folder using terminal and run: `(cd api && npm install) && npm install --legacy-peer-deps` for the dependencies.
5. Run `npm start` to start the application.
## LinkWarden Development ## LinkWarden Development

View File

@ -1,7 +1,7 @@
module.exports.port = process.env.PORT || 5000; module.exports.port = process.env.PORT || 5000;
module.exports.URI = process.env.MONGODB_URI || 'mongodb://localhost:27017'; module.exports.URI = process.env.MONGODB_URI || "mongodb://localhost:27017"; // URI
module.exports.database = process.env.DB_NAME || 'sample_db'; module.exports.database = process.env.DB_NAME || "sample_db"; // Database name
module.exports.collection = process.env.COLLECTION_NAME || 'list'; module.exports.collection = process.env.COLLECTION_NAME || "list"; // Collection name
const storageLocation = process.env.STORAGE_LOCATION || '/media'; const storageLocation = process.env.STORAGE_LOCATION || "./media";
module.exports.screenshotDirectory = storageLocation + '/screenshots'; module.exports.screenshotDirectory = storageLocation + "/screenshots";
module.exports.pdfDirectory = storageLocation + '/pdfs'; module.exports.pdfDirectory = storageLocation + "/pdfs";

View File

@ -4,7 +4,14 @@ const { MongoClient } = require("mongodb");
const cors = require("cors"); const cors = require("cors");
const getData = require("./modules/getData.js"); const getData = require("./modules/getData.js");
const fs = require("fs"); const fs = require("fs");
const { port, URI, database, collection, screenshotDirectory, pdfDirectory } = require("./config.js"); const {
port,
URI,
database,
collection,
screenshotDirectory,
pdfDirectory,
} = require("./config.js");
const fetch = require("cross-fetch"); const fetch = require("cross-fetch");
const sanitize = require("sanitize-filename"); const sanitize = require("sanitize-filename");
@ -21,7 +28,6 @@ if (!fs.existsSync(pdfDirectory)) {
fs.mkdirSync(pdfDirectory, { recursive: true }); fs.mkdirSync(pdfDirectory, { recursive: true });
} }
app.use(cors()); app.use(cors());
app.use(express.json()); app.use(express.json());
@ -33,7 +39,7 @@ app.get("/api", async (req, res) => {
app.get("/screenshots/:id", async (req, res) => { app.get("/screenshots/:id", async (req, res) => {
res.sendFile( res.sendFile(
screenshotDirectory + "/" + sanitize(req.params.id), __dirname + "/" + screenshotDirectory + "/" + sanitize(req.params.id),
(err) => { (err) => {
if (err) { if (err) {
res.sendFile(__dirname + "/pages/404.html"); res.sendFile(__dirname + "/pages/404.html");
@ -43,14 +49,11 @@ app.get("/screenshots/:id", async (req, res) => {
}); });
app.get("/pdfs/:id", async (req, res) => { app.get("/pdfs/:id", async (req, res) => {
res.sendFile( res.sendFile(pdfDirectory + "/" + sanitize(req.params.id), (err) => {
pdfDirectory + "/" + sanitize(req.params.id), if (err) {
(err) => { res.sendFile(__dirname + "/pages/404.html");
if (err) {
res.sendFile(__dirname + "/pages/404.html");
}
} }
); });
}); });
app.post("/api", async (req, res) => { app.post("/api", async (req, res) => {
@ -125,23 +128,17 @@ async function deleteDoc(doc) {
try { try {
const result = await list.deleteOne({ _id: doc }); const result = await list.deleteOne({ _id: doc });
fs.unlink( fs.unlink(screenshotDirectory + "/" + doc + ".png", (err) => {
screenshotDirectory + "/" + doc + ".png", if (err) {
(err) => { console.log(err);
if (err) {
console.log(err);
}
} }
); });
fs.unlink( fs.unlink(pdfDirectory + "/" + doc + ".pdf", (err) => {
pdfDirectory +"/" + doc + ".pdf", if (err) {
(err) => { console.log(err);
if (err) {
console.log(err);
}
} }
); });
return result; return result;
} catch (err) { } catch (err) {

View File

@ -13,7 +13,6 @@ services:
- MONGODB_URI=mongodb://mongo:27017/ - MONGODB_URI=mongodb://mongo:27017/
- PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true - PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
volumes: volumes:
- ./media:/media
- ./api:/home/node - ./api:/home/node
ports: ports:
- 5000:5000 - 5000:5000

View File

@ -1 +0,0 @@
This is the archive storage (For docker).

View File

@ -146,8 +146,6 @@ function App() {
/> />
) : null} ) : null}
{numberOfResults === 0 ? <NoResults /> : null}
{newBox ? ( {newBox ? (
<AddItem <AddItem
SetLoader={SetLoader} SetLoader={SetLoader}
@ -158,6 +156,8 @@ function App() {
/> />
) : null} ) : null}
{numberOfResults === 0 ? <NoResults /> : null}
{loader ? <Loader lightMode={lightMode} /> : null} {loader ? <Loader lightMode={lightMode} /> : null}
</div> </div>

View File

@ -1 +1 @@
export const API_HOST = process.env.REACT_APP_API_HOST || ""; export const API_HOST = process.env.REACT_APP_API_HOST || "http://localhost:5000"; // API full address