Skip to content

Commit

Permalink
fixing more codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lathoub committed Sep 9, 2024
1 parent fce548b commit 8635730
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esversion": 6
}
93 changes: 49 additions & 44 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,82 @@
import express, { json } from 'express'
import cors from 'cors'
import morgan from 'morgan'
import { major } from 'semver'
import favicon from 'serve-favicon'
import { join } from 'path'
import YAML from 'yaml'
import { readFileSync } from 'fs'
import { options as mwOptions } from './middlewares/options.js'
import encodings from './middlewares/encodings.js'
import apiVersion from './middlewares/apiversion.js'
import oapifp1 from './routes/ogcapiFeaturesPart1.js'
import oapifp3 from './routes/ogcapiFeaturesPart3.js'
import oapifp4 from './routes/ogcapiFeaturesPart4.js'
import oapifp5 from './routes/ogcapiFeaturesPart5.js'
import oapipp1 from './routes/ogcapiProcessesPart1Core.js'
import express, { json } from "express";
import cors from "cors";
import morgan from "morgan";
import { major } from "semver";
import favicon from "serve-favicon";
import { join } from "path";
import YAML from "yaml";
import { readFileSync } from "fs";
import { options as mwOptions } from "./middlewares/options.js";
import encodings from "./middlewares/encodings.js";
import apiVersion from "./middlewares/apiversion.js";
import oapifp1 from "./routes/ogcapiFeaturesPart1.js";
import oapifp3 from "./routes/ogcapiFeaturesPart3.js";
import oapifp4 from "./routes/ogcapiFeaturesPart4.js";
import oapifp5 from "./routes/ogcapiFeaturesPart5.js";
import oapipp1 from "./routes/ogcapiProcessesPart1Core.js";

export const app = express()
export const app = express();

const __dirname = import.meta.dirname
if (__dirname === undefined)
console.log('need node 20.16 or higher')
const __dirname = import.meta.dirname;
if (__dirname === undefined) console.log("need node 20.16 or higher");

const configPath = process.env.DATA_PATH || join(__dirname, "../config")
const yamlStr = readFileSync(join(configPath, `${process.env.ID}.yml`))
global.config = YAML.parse(yamlStr.toString())
const configPath = process.env.DATA_PATH || join(__dirname, "../config");
const yamlStr = readFileSync(join(configPath, `${process.env.ID}.yml`));
global.config = YAML.parse(yamlStr.toString());

app.use(morgan(':method :url :response-time', { stream: { write: msg => console.log(msg) } }));
app.use(
morgan(":method :url :response-time", {
stream: { write: (msg) => console.log(msg) },
})
);

// Deal with 'options' prior to cors,
app.options('*', mwOptions)
app.options("*", mwOptions);

// (OAPIF P1) 7.5 Servers implementing CORS will implement the method OPTIONS, too.
// (OAPIF P1) 7.8 Recommendation 5 If the server is intended to be accessed from the browser,
// cross-origin requests SHOULD be supported.
// (OAPIF P1) 7.8 Recommendation 5 If the server is intended to be accessed from the browser,
// cross-origin requests SHOULD be supported.
// Note that support can also be added in a proxy layer on top of the server.
// (OAPIC P1) 8.5 Support for Cross-Origin Requests
app.use(cors()); // Enable All CORS Requests

// For HTML rendering
app.set('view engine', 'pug');
app.set('views', join(__dirname, 'views'));
app.set("view engine", "pug");
app.set("views", join(__dirname, "views"));

app.use(favicon(join(__dirname,'public', 'images', 'favicon.ico')));
app.use(favicon(join(__dirname, "public", "images", "favicon.ico")));

//app.use(express.static(pathToSwaggerUi))
app.use(express.static(join(__dirname, 'public')));
app.use(express.static(join(__dirname, "public")));
app.use(json());

// No need to tell the world what tools we are using, it only gives
// out information to not-so-nice people
app.disable('x-powered-by');
app.disable("x-powered-by");

// setup middleware to decode the content-type
// see http://docs.opengeospatial.org/is/17-069r3/17-069r3.html#_encodings
app.use(encodings)
app.use(encodings);
// (ADR) /core/version-header: Return the full version number in a response header
// https://gitdocumentatie.logius.nl/publicatie/api/adr/#/core/version-header
app.use(apiVersion)
app.use(apiVersion);

// Mount API on this path
const mountPath = process.env.ID // from config
const mountPath = process.env.ID; // from config
// (ADR) /core/uri-version: Include the major version number in the URI
// https://gitdocumentatie.logius.nl/publicatie/api/adr/#/core/uri-version
const serviceRoot = `/${mountPath}/v${major(process.env.APIVERSION)}`
const serviceRoot = `/${mountPath}/v${major(process.env.APIVERSION)}`;

app.use(serviceRoot, oapifp1)
app.use(serviceRoot, oapifp3)
app.use(serviceRoot, oapifp4)
app.use(serviceRoot, oapifp5)
app.use(serviceRoot, oapipp1)
app.use(serviceRoot, oapifp1);
app.use(serviceRoot, oapifp3);
app.use(serviceRoot, oapifp4);
app.use(serviceRoot, oapifp5);
app.use(serviceRoot, oapipp1);

// (ADR) /core/http-methods: Only apply standard HTTP methods
// https://gitdocumentatie.logius.nl/publicatie/api/adr/#/core/http-methods
app.all('*', function (req, res, next) {
res.status(405).json({ 'code': `Method Not Allowed`, 'description': `Not allowed` })
})
app.all("*", function (req, res, next) {
res
.status(405)
.json({ code: `Method Not Allowed`, description: `Not allowed` });
});
6 changes: 3 additions & 3 deletions src/models/styles/styles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import database from '../../database/database.js'
import database from "../../database/database.js";

export default {
get
}
get,
};

0 comments on commit 8635730

Please sign in to comment.