Skip to content

Commit

Permalink
feat(starters): Improve server
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Feb 25, 2022
1 parent 89b5e59 commit c2d2cfc
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions starters/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +25,7 @@ const plugins = [
`medusa-payment-manual`,
];

const config = {
module.exports = {
serverConfig: {
port: PORT,
},
Expand All @@ -35,13 +35,11 @@ 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,
redis_url: REDIS_URL,
},
plugins,
};

export = config;
6 changes: 3 additions & 3 deletions starters/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "adrien2p <[email protected]>",
"homepage": "https://github.com/adrien2p",
"license": "MIT",
"main": "dist/main.js",
"main": "dist/src/main.js",
"files": [
"dist"
],
Expand All @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions starters/server/src/main.ts
Original file line number Diff line number Diff line change
@@ -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
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions starters/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down

0 comments on commit c2d2cfc

Please sign in to comment.