diff --git a/starters/plugin-module/src/modules/user/middlewares/attachUserSubscribers.middleware.ts b/starters/plugin-module/src/modules/user/middlewares/attachUserSubscribers.middleware.ts index c92330ca..b92b34a0 100644 --- a/starters/plugin-module/src/modules/user/middlewares/attachUserSubscribers.middleware.ts +++ b/starters/plugin-module/src/modules/user/middlewares/attachUserSubscribers.middleware.ts @@ -7,7 +7,7 @@ import { Utils as MedusaUtils, } from 'medusa-extender'; import { Connection } from 'typeorm'; -import UserSubscriber from '@modules/user/subscribers/user.subscriber'; +import UserSubscriber from '../subscribers/user.subscriber'; @Middleware({ requireAuth: true, routes: [{ method: 'post', path: '/admin/users/' }] }) export default class AttachUserSubscribersMiddleware { diff --git a/starters/server/README.md b/starters/server/README.md index 69b92b01..5457fb38 100644 --- a/starters/server/README.md +++ b/starters/server/README.md @@ -2,6 +2,8 @@ ## Usage +Update the config according to your needs before starting the server. + ```bash npx degit github:adrien2p/medusa-extender/starters/server#main server cd server diff --git a/starters/server/src/medusa-config.ts b/starters/server/medusa-config.js similarity index 77% rename from starters/server/src/medusa-config.ts rename to starters/server/medusa-config.js index 2ef82b3f..ccc91eea 100644 --- a/starters/server/src/medusa-config.ts +++ b/starters/server/medusa-config.js @@ -9,11 +9,11 @@ switch (process.env.NODE_ENV) { ENV_FILE_NAME = '.env.test'; break; default: - ENV_FILE_NAME = '.env.local'; + ENV_FILE_NAME = '.env'; break; } -dotenv.config({ path: __dirname + '../' + ENV_FILE_NAME }); +dotenv.config({ path: process.cwd() + '/' + ENV_FILE_NAME }); const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379'; const PORT = process.env.PORT || 3000; @@ -25,7 +25,7 @@ const plugins = [ `medusa-payment-manual`, ]; -const config = { +module.exports = { serverConfig: { port: PORT, }, @@ -35,7 +35,7 @@ const config = { jwtSecret: process.env.JWT_SECRET, cookieSecret: process.env.COOKIE_SECRET, - database_url: `postgres://${process.env.DB_HOST}:${process.env.DB_PORT}/medusa`, + database_url: `postgres://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${process.env.DB_HOST}:${process.env.DB_PORT}/medusa`, database_type: 'postgres', store_cors: STORE_CORS, admin_cors: ADMIN_CORS, @@ -43,5 +43,3 @@ const config = { }, plugins, }; - -export = config; diff --git a/starters/server/package.json b/starters/server/package.json index 49e0a8da..0e04cebe 100644 --- a/starters/server/package.json +++ b/starters/server/package.json @@ -6,7 +6,7 @@ "author": "adrien2p ", "homepage": "https://github.com/adrien2p", "license": "MIT", - "main": "dist/main.js", + "main": "dist/src/main.js", "files": [ "dist" ], @@ -17,8 +17,8 @@ "migrate": "ts-node migrate.ts", "build": "rm -rf dist && ./node_modules/.bin/tsc -p tsconfig.json", "format": "./node_modules/.bin/prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "start": "npm run build && NODE_ENV=development node ./dist/main.js", - "start:prod": "npm run build:prod && NODE_ENV=prod node dist/main", + "start": "npm run build && NODE_ENV=development node ./dist/src/main.js", + "start:prod": "npm run build:prod && NODE_ENV=prod node dist/src/main", "test": "NODE_ENV=test jest --detectOpenHandles", "test:watch": "NODE_ENV=test jest --watch --detectOpenHandles", "test:cov": "NODE_ENV=test jest --coverage --detectOpenHandles" diff --git a/starters/server/src/main.ts b/starters/server/src/main.ts index d0de10a8..4713b214 100644 --- a/starters/server/src/main.ts +++ b/starters/server/src/main.ts @@ -1,14 +1,12 @@ import express = require('express'); -import config = require('./medusa-config'); +const config = require('../medusa-config'); import { Medusa } from 'medusa-extender'; -import { resolve } from 'path'; -import { UserModule } from '@modules/user/user.module'; +import { UserModule } from './modules/user/user.module'; async function bootstrap() { const expressInstance = express(); - const rootDir = resolve(__dirname); - await new Medusa(rootDir, expressInstance).load([ + await new Medusa(__dirname + '/../', expressInstance).load([ UserModule ]); diff --git a/starters/server/src/modules/user/middlewares/attachUserSubscribers.middleware.ts b/starters/server/src/modules/user/middlewares/attachUserSubscribers.middleware.ts index c92330ca..b92b34a0 100644 --- a/starters/server/src/modules/user/middlewares/attachUserSubscribers.middleware.ts +++ b/starters/server/src/modules/user/middlewares/attachUserSubscribers.middleware.ts @@ -7,7 +7,7 @@ import { Utils as MedusaUtils, } from 'medusa-extender'; import { Connection } from 'typeorm'; -import UserSubscriber from '@modules/user/subscribers/user.subscriber'; +import UserSubscriber from '../subscribers/user.subscriber'; @Middleware({ requireAuth: true, routes: [{ method: 'post', path: '/admin/users/' }] }) export default class AttachUserSubscribersMiddleware { diff --git a/starters/server/tsconfig.json b/starters/server/tsconfig.json index ddeb39ec..bcedda65 100644 --- a/starters/server/tsconfig.json +++ b/starters/server/tsconfig.json @@ -10,19 +10,16 @@ "sourceMap": true, "skipLibCheck": true, "esModuleInterop": true, + "allowJs": true, "baseUrl": "./src", - "rootDir": "./src", + "rootDir": ".", "lib": [ "es2015.proxy", "es2017" ], - "outDir": "dist", - "paths": { - "@modules/*": [ - "modules/*" - ] - } + "outDir": "dist" }, + "include": ["src", "medusa-config.js"], "exclude": [ "**/node_modules" ]