add env vars for local development

This commit is contained in:
Simon Larsen 2023-09-13 12:03:36 +05:30
parent 13fecdccda
commit 8280d9e7e9
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
5 changed files with 79 additions and 61 deletions

View File

@ -2,8 +2,9 @@ const path = require("path");
const webpack = require("webpack");
const dotenv = require('dotenv');
const express = require('express');
const axios = require('axios');
const readEnvFile = (pathToFile) => {
const readEnvFile = async (pathToFile) => {
const parsed = dotenv.config({ path: pathToFile }).parsed;
@ -13,66 +14,76 @@ const readEnvFile = (pathToFile) => {
env[key] = JSON.stringify(parsed[key]);
}
env['HOST'] = 'localhost' // use localhost for dev.
env['USE_HTTPS'] = true;
// Ping API and get respojse.
const response = await axios.get(`http://localhost/api/`);
return env;
}
module.exports = {
entry: "./src/Index.tsx",
mode: "development",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "public", "dist"),
publicPath: "/accounts/dist/",
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.css', '.scss'],
alias: {
react: path.resolve('./node_modules/react'),
}
},
externals: {
'react-native-sqlite-storage': 'react-native-sqlite-storage'
},
plugins: [
new webpack.DefinePlugin({
'process': {
'env': {
...readEnvFile('/usr/src/app/dev-env/.env')
}
}
}),
],
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: 'ts-loader'
},
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', "sass-loader"]
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader'
}
],
},
devServer: {
historyApiFallback: true,
devMiddleware: {
writeToDisk: true,
const webpackConfig = async () => {
return {
entry: "./src/Index.tsx",
mode: "development",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "public", "dist"),
publicPath: "/accounts/dist/",
},
allowedHosts: "all",
setupMiddlewares: (middlewares, devServer) => {
devServer.app.use('/accounts/assets', express.static(path.resolve(__dirname, 'public', 'assets')));
return middlewares;
}
},
devtool: 'eval-source-map',
}
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.css', '.scss'],
alias: {
react: path.resolve('./node_modules/react'),
}
},
externals: {
'react-native-sqlite-storage': 'react-native-sqlite-storage'
},
plugins: [
new webpack.DefinePlugin({
'process': {
'env': {
...(await readEnvFile('/usr/src/app/dev-env/.env'))
}
}
}),
],
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: 'ts-loader'
},
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', "sass-loader"]
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader'
}
],
},
devServer: {
historyApiFallback: true,
devMiddleware: {
writeToDisk: true,
},
allowedHosts: "all",
setupMiddlewares: (middlewares, devServer) => {
devServer.app.use('/accounts/assets', express.static(path.resolve(__dirname, 'public', 'assets')));
return middlewares;
}
},
devtool: 'eval-source-map',
}
};
module.exports = webpackConfig;

View File

@ -13,6 +13,9 @@ const readEnvFile = (pathToFile) => {
env[key] = JSON.stringify(parsed[key]);
}
env['HOST'] = 'localhost' // use localhost for dev.
env['USE_HTTPS'] = true;
return env;
}

View File

@ -30,9 +30,9 @@ export const env: Function = (key: string): string => {
};
export const HTTP_PROTOCOL: Protocol =
env('HTTP_PROTOCOL') === 'http' ? Protocol.HTTP : Protocol.HTTPS;
env('USE_HTTPS') === true ? Protocol.HTTP : Protocol.HTTPS;
export const HOST: string = env('DOMAIN') || '';
export const HOST: string = env('HOST') || '';
export const BILLING_ENABLED: boolean = env('BILLING_ENABLED') === 'true';
export const BILLING_PUBLIC_KEY: string = env('BILLING_PUBLIC_KEY') || '';

View File

@ -13,6 +13,8 @@ const readEnvFile = (pathToFile) => {
env[key] = JSON.stringify(parsed[key]);
}
env['HOST'] = 'localhost' // use localhost for dev.
env['USE_HTTPS'] = true;
return env;
}

View File

@ -13,6 +13,8 @@ const readEnvFile = (pathToFile) => {
env[key] = JSON.stringify(parsed[key]);
}
env['HOST'] = 'localhost' // use localhost for dev.
env['USE_HTTPS'] = true;
return env;
}