diff --git a/server/.eslintrc.yml b/server/.eslintrc.yml index aee4273..9bf9eb1 100644 --- a/server/.eslintrc.yml +++ b/server/.eslintrc.yml @@ -1,6 +1,7 @@ --- extends: - "@nuxtjs" + - plugin:prettier/recommended plugins: - "@typescript-eslint" parserOptions: diff --git a/server/package.json b/server/package.json index 820280d..40ed558 100644 --- a/server/package.json +++ b/server/package.json @@ -25,7 +25,7 @@ "@typescript-eslint/eslint-plugin": "4.20.0", "@typescript-eslint/parser": "4.20.0", "eslint": "7.23.0", - "eslint-config-prettier": "8.1.0", + "eslint-config-prettier": "^8.1.0", "eslint-plugin-prettier": "3.3.1", "nodemon": "2.0.7", "prettier": "2.2.1", diff --git a/server/src/helpers/port.ts b/server/src/helpers/port.ts index 3035c4c..cadece8 100644 --- a/server/src/helpers/port.ts +++ b/server/src/helpers/port.ts @@ -5,18 +5,18 @@ import { Port } from '../types' * * @since 0.0.0 */ -export function normalizePort (portString:string): Port { - const port = parseInt(portString, 10) +export function normalizePort(portString: string): Port { + const port = parseInt(portString, 10) - if (isNaN(port)) { - // named pipe - return portString - } + if (isNaN(port)) { + // named pipe + return portString + } - if (port >= 0) { - // port number - return port - } + if (port >= 0) { + // port number + return port + } - return false + return false } diff --git a/server/src/helpers/server-callbacks.ts b/server/src/helpers/server-callbacks.ts index 18fb1f0..0aecdc4 100644 --- a/server/src/helpers/server-callbacks.ts +++ b/server/src/helpers/server-callbacks.ts @@ -6,30 +6,28 @@ import type { Debugger } from 'debug' * * @since 0.0.0 */ -export function getErrorCb (port: number | string | boolean) { - return (error: any) => { - if (error.syscall !== 'listen') { - throw error - } +export function getErrorCb(port: number | string | boolean) { + return (error: any) => { + if (error.syscall !== 'listen') { + throw error + } - const bind = typeof port === 'string' - ? 'Pipe ' + port - : 'Port ' + port + const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port - // handle specific listen errors with friendly messages - switch (error.code) { - case 'EACCES': { - console.error(bind + ' requires elevated privileges') - process.exit(1) - } - case 'EADDRINUSE': { - console.error(bind + ' is already in use') - process.exit(1) - } - default: - throw error - } - } + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': { + console.error(bind + ' requires elevated privileges') + process.exit(1) + } + case 'EADDRINUSE': { + console.error(bind + ' is already in use') + process.exit(1) + } + default: + throw error + } + } } /** @@ -37,15 +35,13 @@ export function getErrorCb (port: number | string | boolean) { * * @since 0.0.0 */ -export function getListeningCb (server: http.Server, debug: Debugger) { - return () => { - const addr = server.address() +export function getListeningCb(server: http.Server, debug: Debugger) { + return () => { + const addr = server.address() - if (addr) { - const bind = typeof addr === 'string' - ? 'pipe ' + addr - : 'port ' + addr.port - debug('Listening on ' + bind) - } - } + if (addr) { + const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port + debug('Listening on ' + bind) + } + } } diff --git a/server/src/middlewares.ts b/server/src/middlewares.ts index 3438300..8e42ccc 100644 --- a/server/src/middlewares.ts +++ b/server/src/middlewares.ts @@ -4,10 +4,10 @@ import express from 'express' import cookieParser from 'cookie-parser' import { WEBUI_DIR } from './helpers/paths' -export function registerMiddlewares (app: Application) { - app.use(logger('dev')) - app.use(express.json()) - app.use(express.urlencoded({ extended: false })) - app.use(cookieParser()) - app.use(express.static(WEBUI_DIR)) +export function registerMiddlewares(app: Application) { + app.use(logger('dev')) + app.use(express.json()) + app.use(express.urlencoded({ extended: false })) + app.use(cookieParser()) + app.use(express.static(WEBUI_DIR)) } diff --git a/server/src/routes/api/get/sample.ts b/server/src/routes/api/get/sample.ts index 54ae0f2..9bd955e 100644 --- a/server/src/routes/api/get/sample.ts +++ b/server/src/routes/api/get/sample.ts @@ -3,7 +3,7 @@ import { ApiHandler } from '../../../types' const path: ApiHandler['path'] = '/sample' const handler: ApiHandler['handler'] = (_, res) => { - res.send('Mandi') + res.send('Mandi') } const apiHandler: ApiHandler = { path, handler } diff --git a/server/src/routes/api/register.ts b/server/src/routes/api/register.ts index ee2cafd..c967462 100644 --- a/server/src/routes/api/register.ts +++ b/server/src/routes/api/register.ts @@ -1,11 +1,12 @@ -import { Application } from 'express' -import { ApiHandler } from '../../types' +import type { Application } from 'express' +import type { ApiHandler } from '../../types' + import getEndpoints from './get' import deleteEndpoints from './delete' import postEndpoints from './post' import patchEndpoints from './patch' -const prependApiPath = (path:string) => `/api${path}` +const prependApiPath = (path: string) => `/api${path}` interface Method { method: string @@ -13,29 +14,29 @@ interface Method { } const methods: Method[] = [ - { - method: 'get', - endpoints: getEndpoints - }, - { - method: 'delete', - endpoints: deleteEndpoints - }, - { - method: 'post', - endpoints: postEndpoints - }, - { - method: 'patch', - endpoints: patchEndpoints - } + { + method: 'get', + endpoints: getEndpoints + }, + { + method: 'delete', + endpoints: deleteEndpoints + }, + { + method: 'post', + endpoints: postEndpoints + }, + { + method: 'patch', + endpoints: patchEndpoints + } ] -export function registerApis (app: Application) { - methods.forEach(({ method, endpoints }) => { - endpoints.forEach((endpoint) => { - // @ts-ignore - app[method](prependApiPath(endpoint.path), endpoint.handler) - }) - }) +export function registerApis(app: Application) { + methods.forEach(({ method, endpoints }) => { + endpoints.forEach(endpoint => { + // @ts-ignore + app[method](prependApiPath(endpoint.path), endpoint.handler) + }) + }) } diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index be2ba5e..05fa79b 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -8,7 +8,7 @@ const router = express.Router() * @since 0.0.0 */ router.get('/', (_, res) => { - res.render('index', { title: 'Express' }) + res.render('index', { title: 'Express' }) }) export default router diff --git a/server/src/routes/users.ts b/server/src/routes/users.ts index ba5cc06..5777fcb 100644 --- a/server/src/routes/users.ts +++ b/server/src/routes/users.ts @@ -8,7 +8,7 @@ const router = express.Router() * @since 0.0.0 */ router.get('/', (_, res) => { - res.send('respond with a resource') + res.send('respond with a resource') }) export default router diff --git a/server/yarn.lock b/server/yarn.lock index 8548b52..90de73f 100644 --- a/server/yarn.lock +++ b/server/yarn.lock @@ -1116,7 +1116,7 @@ escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= -eslint-config-prettier@8.1.0: +eslint-config-prettier@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.1.0.tgz#4ef1eaf97afe5176e6a75ddfb57c335121abc5a6" integrity sha512-oKMhGv3ihGbCIimCAjqkdzx2Q+jthoqnXSP+d86M9tptwugycmTFdVR4IpLgq2c4SHifbwO90z2fQ8/Aio73yw==