From 4ca38b8a634f55cd53a16807f731d2f572362dc6 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Mon, 23 May 2016 22:55:42 -0700 Subject: [PATCH] more settings --- index.js | 2 -- server/routes.js | 15 ++++++++++----- src/Constants.js | 9 +++++---- webpack.config.dev.js | 7 ++++++- webpack.config.js | 4 +--- webpack.config.prod.js | 2 ++ 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index ef37f8d4c..0ac7c2d07 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,6 @@ require('./init'); var app = require('./server').default; var http = require('http'); -console.log(process.env); - var server = http.createServer(app.callback()); server.listen(process.env.PORT || '3000'); server.on('error', (err) => { diff --git a/server/routes.js b/server/routes.js index 2b762635f..89f5e31d3 100644 --- a/server/routes.js +++ b/server/routes.js @@ -28,12 +28,17 @@ if (process.env.NODE_ENV === 'production') { console.log(path.join(__dirname, '../dist/', ctx.path.substring(8))); const stats = await sendfile(ctx, path.join(__dirname, '../dist/', ctx.path.substring(8))); }); -} -router.get('*', async (ctx) => { - const stats = await sendfile(ctx, path.join(__dirname, '../dist/index.html')); - if (!ctx.status) ctx.throw(httpErrors.NotFound()); -}); + router.get('*', async (ctx) => { + const stats = await sendfile(ctx, path.join(__dirname, '../dist/index.html')); + if (!ctx.status) ctx.throw(httpErrors.NotFound()); + }); +} else { + router.get('*', async (ctx) => { + const stats = await sendfile(ctx, path.join(__dirname, './static/dev.html')); + if (!ctx.status) ctx.throw(httpErrors.NotFound()); + }); +} koa.use(router.routes()); diff --git a/src/Constants.js b/src/Constants.js index 6a4f9e1b6..85593dd6a 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -1,7 +1,8 @@ -// Constant values -const constants = { +let constants; + +constants = { API_USER_AGENT: `Atlas`, - API_BASE_URL: 'http://localhost:3000/api', + API_BASE_URL: '/api', }; -export default Object.assign(keys, constants); +export default constants; diff --git a/webpack.config.dev.js b/webpack.config.dev.js index bd607538b..154c4d4ba 100644 --- a/webpack.config.dev.js +++ b/webpack.config.dev.js @@ -1,5 +1,6 @@ -var path = require('path'); var webpack = require('webpack'); +var HtmlWebpackPlugin = require('html-webpack-plugin'); +var ExtractTextPlugin = require("extract-text-webpack-plugin"); const commonWebpackConfig = require('./webpack.config'); @@ -15,5 +16,9 @@ const developmentWebpackConfig = Object.assign(commonWebpackConfig, { developmentWebpackConfig.plugins.push(new webpack.optimize.OccurenceOrderPlugin()); developmentWebpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin()); developmentWebpackConfig.plugins.push(new webpack.NoErrorsPlugin()); +developmentWebpackConfig.plugins.push(new ExtractTextPlugin('styles.css')); +developmentWebpackConfig.plugins.push(new HtmlWebpackPlugin({ + title: 'Atlas', +})); module.exports = developmentWebpackConfig; diff --git a/webpack.config.js b/webpack.config.js index 57f797294..7d22505d0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,6 @@ var path = require('path'); var webpack = require('webpack'); var ExtractTextPlugin = require("extract-text-webpack-plugin"); -var HtmlWebpackPlugin = require('html-webpack-plugin'); // Load .env require('dotenv').config(); @@ -38,7 +37,7 @@ module.exports = { ] }, resolve: { - root: path.resolve('./src'), + root: path.join(__dirname, 'src'), // you can now require('file') instead of require('file.json') extensions: ['', '.js', '.json'] }, @@ -47,6 +46,5 @@ module.exports = { new webpack.ProvidePlugin({ 'fetch': 'imports?this=>global!exports?global.fetch!isomorphic-fetch' }), - new ExtractTextPlugin('styles.[hash].css'), ] }; \ No newline at end of file diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 5f370b916..1d1d6e179 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -1,6 +1,7 @@ var path = require('path'); var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); +var ExtractTextPlugin = require("extract-text-webpack-plugin"); commonWebpackConfig = require('./webpack.config'); @@ -20,6 +21,7 @@ productionWebpackConfig = Object.assign(commonWebpackConfig, { productionWebpackConfig.plugins.push(new HtmlWebpackPlugin({ template: 'server/static/index.html' })); +productionWebpackConfig.plugins.push(new ExtractTextPlugin('styles.[hash].css')); productionWebpackConfig.plugins.push(new webpack.optimize.OccurenceOrderPlugin()); productionWebpackConfig.plugins.push( new webpack.optimize.UglifyJsPlugin({