Skip to content

Commit

Permalink
fix: fix issue with starting api in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fruneen committed Mar 26, 2024
1 parent d000aac commit 8a0f4fb
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 172 deletions.
2 changes: 1 addition & 1 deletion template/apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
"tsconfig": "workspace:*",
"typescript": "5.3.3"
"typescript": "5.2.2"
},
"lint-staged": {
"*.ts": [
Expand Down
25 changes: 14 additions & 11 deletions template/apps/api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
// allows to require modules relative to /src folder
// for example: require('lib/mongo/idGenerator')
// all options can be found here: https://gist.github.com/branneman/8048520
/* eslint-disable simple-import-sort/imports, import/newline-after-import, import/first */
// Allows requiring modules relative to /src folder,
// For example, require('lib/mongo/idGenerator')
// All options can be found here: https://gist.github.com/branneman/8048520
import moduleAlias from 'module-alias';
moduleAlias.addPath(__dirname);
moduleAlias(); // read aliases from package json

import 'dotenv/config';

import cors from '@koa/cors';
import http from 'http';
import ioEmitter from 'io-emitter';
import bodyParser from 'koa-bodyparser';
import helmet from 'koa-helmet';
import koaLogger from 'koa-logger';
import qs from 'koa-qs';
import logger from 'logger';
import moduleAlias from 'module-alias'; // read aliases from package json
import redisClient, { redisErrorHandler } from 'redis-client';

import { socketService } from 'services';
import routes from 'routes';

import config from 'config';

import { AppKoa } from 'types';
import ioEmitter from 'io-emitter';
import redisClient, { redisErrorHandler } from 'redis-client';

import 'dotenv/config';
import logger from 'logger';

moduleAlias.addPath(__dirname);
moduleAlias();
import { AppKoa } from 'types';

const initKoa = () => {
const app = new AppKoa();
Expand Down
4 changes: 3 additions & 1 deletion template/apps/api/src/io-emitter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Emitter } from '@socket.io/redis-emitter';
import logger from 'logger';

import redisClient, { redisErrorHandler } from 'redis-client';

import logger from 'logger';

let emitter: Emitter | null = null;

const publish = (roomId: string | string[], eventName: string, data: unknown) => {
Expand Down
3 changes: 2 additions & 1 deletion template/apps/api/src/migrator/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { generateId } from '@paralect/node-mongo';
import logger from 'logger';
import moment from 'moment';

import logger from 'logger';

import migrationLogService from './migration-log/migration-log.service';
import migrationVersionService from './migration-version/migration-version.service';
import { Migration } from './types';
Expand Down
3 changes: 2 additions & 1 deletion template/apps/api/src/redis-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Redis } from 'ioredis';
import logger from 'logger';

import config from 'config';

import logger from 'logger';

const client = new Redis(config.REDIS_URI as string, {
lazyConnect: true,
retryStrategy: (times) => {
Expand Down
2 changes: 2 additions & 0 deletions template/apps/api/src/resources/user/user.handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { eventBus, InMemoryEvent } from '@paralect/node-mongo';

import ioEmitter from 'io-emitter';

import logger from 'logger';

import { DATABASE_DOCUMENTS } from 'app-constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logger from 'logger';

import { userService } from 'resources/user';

import config from 'config';

import logger from 'logger';

import { AppKoaContext, Next, ValidationErrors } from 'types';

interface CustomError extends Error {
Expand Down
3 changes: 2 additions & 1 deletion template/apps/api/src/scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// allows to require modules relative to /src folder
// for example: require('lib/mongo/idGenerator')
// all options can be found here: https://gist.github.com/branneman/8048520
import logger from 'logger';
import moduleAlias from 'module-alias'; // read aliases from package json

import logger from 'logger';

import 'dotenv/config';
import 'scheduler/cron';
import 'scheduler/handlers/action.example.handler';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logger from 'logger';

import cron from 'scheduler/cron';

import config from 'config';

import logger from 'logger';

const schedule = {
development: 'cron:every-minute',
staging: 'cron:every-minute',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logger from 'logger';
import Mixpanel from 'mixpanel';

import config from 'config';

import logger from 'logger';

const mixpanel = config.MIXPANEL_API_KEY ? Mixpanel.init(config.MIXPANEL_API_KEY, { debug: config.IS_DEV }) : null;

const track = (event: string, data = {}) => {
Expand Down
3 changes: 2 additions & 1 deletion template/apps/api/src/services/email/email.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sendgrid from '@sendgrid/mail';
import logger from 'logger';
import { renderEmailHtml, Template } from 'mailer';

import config from 'config';

import logger from 'logger';

import { EmailServiceConstructorProps, From, SendSendgridTemplateParams, SendTemplateParams } from './email.types';

class EmailService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ParameterizedContext } from 'koa';
import rateLimit from 'koa-ratelimit';

import redisClient from 'redis-client';

import { AppKoaContextState } from 'types';
Expand Down
6 changes: 4 additions & 2 deletions template/apps/api/src/services/socket/socket.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { createAdapter } from '@socket.io/redis-adapter';
import http from 'http';
import logger from 'logger';
import pubClient, { redisErrorHandler } from 'redis-client';
import { Server } from 'socket.io';

import { tokenService } from 'resources/token';

import pubClient, { redisErrorHandler } from 'redis-client';

import logger from 'logger';

import { COOKIES } from 'app-constants';

import socketHelper from './socket.helper';
Expand Down
2 changes: 1 addition & 1 deletion template/apps/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"rootDir": ".",
"baseUrl": "src",
"jsx": "preserve"
"jsx": "react" // for using Mailer
},
"include": ["**/*.ts", "**/*.json"]
}
2 changes: 1 addition & 1 deletion template/apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"storybook": "7.6.14",
"storybook-dark-mode": "3.0.3",
"tsconfig": "workspace:*",
"typescript": "5.3.3"
"typescript": "5.2.2"
},
"lint-staged": {
"*.{ts,tsx}": [
Expand Down
8 changes: 7 additions & 1 deletion template/packages/eslint-config-custom/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ module.exports = {
'error',
{
groups: [
// Allows requiring modules relative to /src folder
['^module-alias'],
// App environment variables
['^\\dotenv/config'],
// Third-party libraries and frameworks
['^@?\\w'],
// Particular business entities
Expand All @@ -128,7 +132,9 @@ module.exports = {
// App config file
['^config'],
// App core modules
['^db'],
['^db', '^io-emitter', '^redis-client'],
// Logger instance
['^logger'],
// Internal packages
['^app-constants', '^schemas', '^types'],
// Relative imports
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions template/packages/tsconfig/nodejs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"display": "Node.js",
"extends": "./base.json",
"compilerOptions": {
"moduleResolution": "NodeNext",
"lib": ["es2023"],
"module": "node16",
"module": "NodeNext",
"target": "es2022",

"allowSyntheticDefaultImports": true,
"useUnknownInCatchVariables": true
},
"ts-node": { "transpileOnly": true }
}
}
Loading

0 comments on commit 8a0f4fb

Please sign in to comment.