Skip to content

Commit

Permalink
remove env.ts file async-labs#139
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Jan 25, 2021
1 parent 34a15a4 commit 1177c65
Show file tree
Hide file tree
Showing 59 changed files with 130 additions and 811 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ All code in this repository is provided under the [MIT License](https://github.c
│ │ │ └── sum.ts
│ │ ├── aws-s3.ts
│ │ ├── aws-ses.ts
│ │ ├── env.ts
│ │ ├── google-auth.ts
│ │ ├── logger.ts
│ │ ├── mailchimp.ts
Expand Down
18 changes: 0 additions & 18 deletions book/10-begin/api/server/env.ts

This file was deleted.

4 changes: 3 additions & 1 deletion book/10-begin/api/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './env';
import * as mongoSessionStore from 'connect-mongo';
import * as cors from 'cors';
import * as express from 'express';
Expand All @@ -12,6 +11,9 @@ import { setupPasswordless } from './passwordless-auth';
import { setupSockets } from './sockets';
import { stripeWebhookAndCheckoutCallback } from './stripe';

// eslint-disable-next-line
require('dotenv').config();

const options = {
useNewUrlParser: true,
useCreateIndex: true,
Expand Down
15 changes: 5 additions & 10 deletions book/10-begin/app/lib/api/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ import sendRequestAndGetResponse from './sendRequestAndGetResponse';

const BASE_PATH = '/api/v1/public';

export const getUserApiMethod = (opts = {}) =>
sendRequestAndGetResponse(
`${BASE_PATH}/get-user`,
Object.assign(
{
method: 'GET',
},
opts,
),
);
export const getUserApiMethod = (request) =>
sendRequestAndGetResponse(`${BASE_PATH}/get-user`, {
request,
method: 'GET',
});

export const getUserBySlugApiMethod = (slug) =>
sendRequestAndGetResponse(`${BASE_PATH}/get-user-by-slug`, {
Expand Down
18 changes: 0 additions & 18 deletions book/10-end/api/server/env.ts

This file was deleted.

4 changes: 3 additions & 1 deletion book/10-end/api/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './env';
import * as mongoSessionStore from 'connect-mongo';
import * as cors from 'cors';
import * as express from 'express';
Expand All @@ -17,6 +16,9 @@ import logger from './logger';
import * as compression from 'compression';
import * as helmet from 'helmet';

// eslint-disable-next-line
require('dotenv').config();

const dev = process.env.NODE_ENV !== 'production';
const port = process.env.PORT || 8000;

Expand Down
15 changes: 5 additions & 10 deletions book/10-end/app/lib/api/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ import sendRequestAndGetResponse from './sendRequestAndGetResponse';

const BASE_PATH = '/api/v1/public';

export const getUserApiMethod = (opts = {}) =>
sendRequestAndGetResponse(
`${BASE_PATH}/get-user`,
Object.assign(
{
method: 'GET',
},
opts,
),
);
export const getUserApiMethod = (request) =>
sendRequestAndGetResponse(`${BASE_PATH}/get-user`, {
request,
method: 'GET',
});

export const getUserBySlugApiMethod = (slug) =>
sendRequestAndGetResponse(`${BASE_PATH}/get-user-by-slug`, {
Expand Down
2 changes: 1 addition & 1 deletion book/10-end/lambda/api
18 changes: 0 additions & 18 deletions book/3-end/api/server/env.ts

This file was deleted.

30 changes: 6 additions & 24 deletions book/3-end/api/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import './env';
import * as express from 'express';

// eslint-disable-next-line
require('dotenv').config();

const server = express();

server.use(express.json());
Expand All @@ -14,31 +16,11 @@ server.get('*', (_, res) => {
res.sendStatus(403);
});

server.listen(process.env.PORT_API, (err) => {
console.log(process.env.PORT_API, process.env.URL_API);

server.listen(process.env['PORT_API'], (err) => {
if (err) {
throw err;
}
console.log(`> Ready on ${process.env.URL_API}`);
});

// import './env';
// import * as express from 'express';
// import api from './api';
// import logger from './logs';

// const server = express();

// server.use(express.json());

// api(server);

// server.get('*', (_, res) => {
// res.sendStatus(403);
// });

// server.listen(process.env.PORT, (err) => {
// if (err) {
// throw err;
// }
// logger.info(`> Ready on ${process.env.ROOT_URL}`);
// });
2 changes: 1 addition & 1 deletion book/3-end/app/lib/api/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sendRequestAndGetResponse from './sendRequestAndGetResponse';

const BASE_PATH = '/api/v1/public';

export const getUser = (request) =>
export const getUserApiMethod = (request) =>
sendRequestAndGetResponse(`${BASE_PATH}/get-user`, {
request,
method: 'GET',
Expand Down
4 changes: 2 additions & 2 deletions book/3-end/app/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import NProgress from 'nprogress';

import confirm from '../lib/confirm';
import notify from '../lib/notify';
import { getUser } from '../lib/api/public';
import { getUserApiMethod } from '../lib/api/public';

type Props = { user: { email: string } };

class Index extends React.Component<Props> {
public static async getInitialProps(ctx) {
const { req } = ctx;

const user = await getUser(req);
const user = await getUserApiMethod(req);

console.log(user);

Expand Down
2 changes: 2 additions & 0 deletions book/3-end/app/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ app.prepare().then(() => {
handle(req, res);
});

console.log(process.env.PORT_APP);

server.listen(process.env.PORT_APP, (err) => {
if (err) {
throw err;
Expand Down
18 changes: 0 additions & 18 deletions book/4-begin/api/server/env.ts

This file was deleted.

4 changes: 3 additions & 1 deletion book/4-begin/api/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import './env';
import * as express from 'express';

// eslint-disable-next-line
require('dotenv').config();

const server = express();

server.use(express.json());
Expand Down
2 changes: 1 addition & 1 deletion book/4-begin/app/lib/api/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sendRequestAndGetResponse from './sendRequestAndGetResponse';

const BASE_PATH = '/api/v1/public';

export const getUser = (request) =>
export const getUserApiMethod = (request) =>
sendRequestAndGetResponse(`${BASE_PATH}/get-user`, {
request,
method: 'GET',
Expand Down
4 changes: 2 additions & 2 deletions book/4-begin/app/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import NProgress from 'nprogress';

import confirm from '../lib/confirm';
import notify from '../lib/notify';
import { getUser } from '../lib/api/public';
import { getUserApiMethod } from '../lib/api/public';

type Props = { user: { email: string } };

class Index extends React.Component<Props> {
public static async getInitialProps(ctx) {
const { req } = ctx;

const user = await getUser(req);
const user = await getUserApiMethod(req);

console.log(user);

Expand Down
52 changes: 0 additions & 52 deletions book/4-begin/app/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,3 @@ app.prepare().then(() => {
console.log(`> Ready on ${process.env.URL_APP}`);
});
});

// import './env';

// import express from 'express';
// import next from 'next';

// import { getUser } from '../lib/api/public';

// const NODE_ENV = process.env.NODE_ENV || 'development';
// const IS_DEV = NODE_ENV !== 'production';

// const app = next({ dev: IS_DEV });
// const handle = app.getRequestHandler();

// app.prepare().then(() => {
// const server = express();

// // give all Nextjs's request to Nextjs before anything else
// server.get('/_next/*', (req, res) => {
// handle(req, res);
// });

// server.use(express.json());

// // middleware that populates req.user via fetching from API
// server.use(async (req: any, _, nextfn) => {
// const headers: any = {};
// if (req.headers && req.headers.cookie) {
// headers.cookie = req.headers.cookie;
// }

// try {
// const { user } = await getUser({ headers });
// req.user = user;
// } catch (error) {
// console.log(error);
// }

// nextfn();
// });

// server.all('*', (req, res) => {
// handle(req, res);
// });

// server.listen(process.env.PORT_APP, (err) => {
// if (err) {
// throw err;
// }
// console.log(`> Ready on ${process.env.URL_APP}`);
// });
// });
18 changes: 0 additions & 18 deletions book/4-end/api/server/env.ts

This file was deleted.

4 changes: 3 additions & 1 deletion book/4-end/api/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import './env';
import * as cors from 'cors';
import * as express from 'express';
import * as mongoose from 'mongoose';

import api from './api';

// eslint-disable-next-line
require('dotenv').config();

const options = {
useNewUrlParser: true,
useCreateIndex: true,
Expand Down
10 changes: 5 additions & 5 deletions book/4-end/app/lib/api/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import sendRequestAndGetResponse from './sendRequestAndGetResponse';

const BASE_PATH = '/api/v1/public';

// export const getUser = (request) =>
// sendRequestAndGetResponse(`${BASE_PATH}/get-user`, {
// request,
// method: 'GET',
// });
export const getUserApiMethod = (request) =>
sendRequestAndGetResponse(`${BASE_PATH}/get-user`, {
request,
method: 'GET',
});

export const getUserBySlugApiMethod = (slug) =>
sendRequestAndGetResponse(`${BASE_PATH}/get-user-by-slug`, {
Expand Down
Loading

0 comments on commit 1177c65

Please sign in to comment.