From 7f36b4bd3610acd1eecfd249e03592d028d69416 Mon Sep 17 00:00:00 2001 From: Bambang Handoko Date: Tue, 21 Mar 2017 11:18:03 +0700 Subject: [PATCH 1/5] first initiate house-selling project --- client/.babelrc | 14 ++ client/.editorconfig | 9 ++ client/.gitignore | 8 ++ client/.postcssrc.js | 8 ++ client/README.md | 30 +++++ client/build/build.js | 35 +++++ client/build/check-versions.js | 45 +++++++ client/build/dev-client.js | 9 ++ client/build/dev-server.js | 83 ++++++++++++ client/build/utils.js | 71 +++++++++++ client/build/vue-loader.conf.js | 12 ++ client/build/webpack.base.conf.js | 58 +++++++++ client/build/webpack.dev.conf.js | 35 +++++ client/build/webpack.prod.conf.js | 120 ++++++++++++++++++ client/build/webpack.test.conf.js | 24 ++++ client/config/dev.env.js | 6 + client/config/index.js | 38 ++++++ client/config/prod.env.js | 3 + client/config/test.env.js | 6 + client/index.html | 11 ++ client/package.json | 83 ++++++++++++ client/src/App.vue | 23 ++++ client/src/assets/logo.png | Bin 0 -> 6849 bytes client/src/components/Hello.vue | 53 ++++++++ client/src/main.js | 15 +++ client/src/router/index.js | 15 +++ client/static/.gitkeep | 0 .../e2e/custom-assertions/elementCount.js | 26 ++++ client/test/e2e/nightwatch.conf.js | 46 +++++++ client/test/e2e/runner.js | 31 +++++ client/test/e2e/specs/test.js | 19 +++ client/test/unit/.eslintrc | 9 ++ client/test/unit/index.js | 16 +++ client/test/unit/karma.conf.js | 33 +++++ client/test/unit/specs/Hello.spec.js | 11 ++ server/app.js | 40 ++++++ server/bin/www | 90 +++++++++++++ server/config/config.js | 35 +++++ server/package.json | 20 +++ server/routes/index.js | 9 ++ 40 files changed, 1199 insertions(+) create mode 100644 client/.babelrc create mode 100644 client/.editorconfig create mode 100644 client/.gitignore create mode 100644 client/.postcssrc.js create mode 100644 client/README.md create mode 100644 client/build/build.js create mode 100644 client/build/check-versions.js create mode 100644 client/build/dev-client.js create mode 100644 client/build/dev-server.js create mode 100644 client/build/utils.js create mode 100644 client/build/vue-loader.conf.js create mode 100644 client/build/webpack.base.conf.js create mode 100644 client/build/webpack.dev.conf.js create mode 100644 client/build/webpack.prod.conf.js create mode 100644 client/build/webpack.test.conf.js create mode 100644 client/config/dev.env.js create mode 100644 client/config/index.js create mode 100644 client/config/prod.env.js create mode 100644 client/config/test.env.js create mode 100644 client/index.html create mode 100644 client/package.json create mode 100644 client/src/App.vue create mode 100644 client/src/assets/logo.png create mode 100644 client/src/components/Hello.vue create mode 100644 client/src/main.js create mode 100644 client/src/router/index.js create mode 100644 client/static/.gitkeep create mode 100644 client/test/e2e/custom-assertions/elementCount.js create mode 100644 client/test/e2e/nightwatch.conf.js create mode 100644 client/test/e2e/runner.js create mode 100644 client/test/e2e/specs/test.js create mode 100644 client/test/unit/.eslintrc create mode 100644 client/test/unit/index.js create mode 100644 client/test/unit/karma.conf.js create mode 100644 client/test/unit/specs/Hello.spec.js create mode 100644 server/app.js create mode 100755 server/bin/www create mode 100644 server/config/config.js create mode 100644 server/package.json create mode 100644 server/routes/index.js diff --git a/client/.babelrc b/client/.babelrc new file mode 100644 index 0000000..13f0e47 --- /dev/null +++ b/client/.babelrc @@ -0,0 +1,14 @@ +{ + "presets": [ + ["env", { "modules": false }], + "stage-2" + ], + "plugins": ["transform-runtime"], + "comments": false, + "env": { + "test": { + "presets": ["env", "stage-2"], + "plugins": [ "istanbul" ] + } + } +} diff --git a/client/.editorconfig b/client/.editorconfig new file mode 100644 index 0000000..9d08a1a --- /dev/null +++ b/client/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..d53c636 --- /dev/null +++ b/client/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +node_modules/ +dist/ +npm-debug.log +yarn-error.log +test/unit/coverage +test/e2e/reports +selenium-debug.log diff --git a/client/.postcssrc.js b/client/.postcssrc.js new file mode 100644 index 0000000..ea9a5ab --- /dev/null +++ b/client/.postcssrc.js @@ -0,0 +1,8 @@ +// https://github.com/michael-ciniawsky/postcss-load-config + +module.exports = { + "plugins": { + // to edit target browsers: use "browserlist" field in package.json + "autoprefixer": {} + } +} diff --git a/client/README.md b/client/README.md new file mode 100644 index 0000000..49ffad9 --- /dev/null +++ b/client/README.md @@ -0,0 +1,30 @@ +# house-selling + +> A Vue.js project + +## Build Setup + +``` bash +# install dependencies +npm install + +# serve with hot reload at localhost:8080 +npm run dev + +# build for production with minification +npm run build + +# build for production and view the bundle analyzer report +npm run build --report + +# run unit tests +npm run unit + +# run e2e tests +npm run e2e + +# run all tests +npm test +``` + +For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). diff --git a/client/build/build.js b/client/build/build.js new file mode 100644 index 0000000..6b8add1 --- /dev/null +++ b/client/build/build.js @@ -0,0 +1,35 @@ +require('./check-versions')() + +process.env.NODE_ENV = 'production' + +var ora = require('ora') +var rm = require('rimraf') +var path = require('path') +var chalk = require('chalk') +var webpack = require('webpack') +var config = require('../config') +var webpackConfig = require('./webpack.prod.conf') + +var spinner = ora('building for production...') +spinner.start() + +rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { + if (err) throw err + webpack(webpackConfig, function (err, stats) { + spinner.stop() + if (err) throw err + process.stdout.write(stats.toString({ + colors: true, + modules: false, + children: false, + chunks: false, + chunkModules: false + }) + '\n\n') + + console.log(chalk.cyan(' Build complete.\n')) + console.log(chalk.yellow( + ' Tip: built files are meant to be served over an HTTP server.\n' + + ' Opening index.html over file:// won\'t work.\n' + )) + }) +}) diff --git a/client/build/check-versions.js b/client/build/check-versions.js new file mode 100644 index 0000000..6548ba1 --- /dev/null +++ b/client/build/check-versions.js @@ -0,0 +1,45 @@ +var chalk = require('chalk') +var semver = require('semver') +var packageConfig = require('../package.json') + +function exec (cmd) { + return require('child_process').execSync(cmd).toString().trim() +} + +var versionRequirements = [ + { + name: 'node', + currentVersion: semver.clean(process.version), + versionRequirement: packageConfig.engines.node + }, + { + name: 'npm', + currentVersion: exec('npm --version'), + versionRequirement: packageConfig.engines.npm + } +] + +module.exports = function () { + var warnings = [] + for (var i = 0; i < versionRequirements.length; i++) { + var mod = versionRequirements[i] + if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { + warnings.push(mod.name + ': ' + + chalk.red(mod.currentVersion) + ' should be ' + + chalk.green(mod.versionRequirement) + ) + } + } + + if (warnings.length) { + console.log('') + console.log(chalk.yellow('To use this template, you must update following to modules:')) + console.log() + for (var i = 0; i < warnings.length; i++) { + var warning = warnings[i] + console.log(' ' + warning) + } + console.log() + process.exit(1) + } +} diff --git a/client/build/dev-client.js b/client/build/dev-client.js new file mode 100644 index 0000000..18aa1e2 --- /dev/null +++ b/client/build/dev-client.js @@ -0,0 +1,9 @@ +/* eslint-disable */ +require('eventsource-polyfill') +var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') + +hotClient.subscribe(function (event) { + if (event.action === 'reload') { + window.location.reload() + } +}) diff --git a/client/build/dev-server.js b/client/build/dev-server.js new file mode 100644 index 0000000..0a1a406 --- /dev/null +++ b/client/build/dev-server.js @@ -0,0 +1,83 @@ +require('./check-versions')() + +var config = require('../config') +if (!process.env.NODE_ENV) { + process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) +} + +var opn = require('opn') +var path = require('path') +var express = require('express') +var webpack = require('webpack') +var proxyMiddleware = require('http-proxy-middleware') +var webpackConfig = process.env.NODE_ENV === 'testing' + ? require('./webpack.prod.conf') + : require('./webpack.dev.conf') + +// default port where dev server listens for incoming traffic +var port = process.env.PORT || config.dev.port +// automatically open browser, if not set will be false +var autoOpenBrowser = !!config.dev.autoOpenBrowser +// Define HTTP proxies to your custom API backend +// https://github.com/chimurai/http-proxy-middleware +var proxyTable = config.dev.proxyTable + +var app = express() +var compiler = webpack(webpackConfig) + +var devMiddleware = require('webpack-dev-middleware')(compiler, { + publicPath: webpackConfig.output.publicPath, + quiet: true +}) + +var hotMiddleware = require('webpack-hot-middleware')(compiler, { + log: () => {} +}) +// force page reload when html-webpack-plugin template changes +compiler.plugin('compilation', function (compilation) { + compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { + hotMiddleware.publish({ action: 'reload' }) + cb() + }) +}) + +// proxy api requests +Object.keys(proxyTable).forEach(function (context) { + var options = proxyTable[context] + if (typeof options === 'string') { + options = { target: options } + } + app.use(proxyMiddleware(options.filter || context, options)) +}) + +// handle fallback for HTML5 history API +app.use(require('connect-history-api-fallback')()) + +// serve webpack bundle output +app.use(devMiddleware) + +// enable hot-reload and state-preserving +// compilation error display +app.use(hotMiddleware) + +// serve pure static assets +var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) +app.use(staticPath, express.static('./static')) + +var uri = 'http://localhost:' + port + +devMiddleware.waitUntilValid(function () { + console.log('> Listening at ' + uri + '\n') +}) + +module.exports = app.listen(port, function (err) { + if (err) { + console.log(err) + return + } + + // when env is testing, don't need open it + if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { + opn(uri) + } +}) diff --git a/client/build/utils.js b/client/build/utils.js new file mode 100644 index 0000000..3f2ef2a --- /dev/null +++ b/client/build/utils.js @@ -0,0 +1,71 @@ +var path = require('path') +var config = require('../config') +var ExtractTextPlugin = require('extract-text-webpack-plugin') + +exports.assetsPath = function (_path) { + var assetsSubDirectory = process.env.NODE_ENV === 'production' + ? config.build.assetsSubDirectory + : config.dev.assetsSubDirectory + return path.posix.join(assetsSubDirectory, _path) +} + +exports.cssLoaders = function (options) { + options = options || {} + + var cssLoader = { + loader: 'css-loader', + options: { + minimize: process.env.NODE_ENV === 'production', + sourceMap: options.sourceMap + } + } + + // generate loader string to be used with extract text plugin + function generateLoaders (loader, loaderOptions) { + var loaders = [cssLoader] + if (loader) { + loaders.push({ + loader: loader + '-loader', + options: Object.assign({}, loaderOptions, { + sourceMap: options.sourceMap + }) + }) + } + + // Extract CSS when that option is specified + // (which is the case during production build) + if (options.extract) { + return ExtractTextPlugin.extract({ + use: loaders, + fallback: 'vue-style-loader' + }) + } else { + return ['vue-style-loader'].concat(loaders) + } + } + + // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html + return { + css: generateLoaders(), + postcss: generateLoaders(), + less: generateLoaders('less'), + sass: generateLoaders('sass', { indentedSyntax: true }), + scss: generateLoaders('sass'), + stylus: generateLoaders('stylus'), + styl: generateLoaders('stylus') + } +} + +// Generate loaders for standalone style files (outside of .vue) +exports.styleLoaders = function (options) { + var output = [] + var loaders = exports.cssLoaders(options) + for (var extension in loaders) { + var loader = loaders[extension] + output.push({ + test: new RegExp('\\.' + extension + '$'), + use: loader + }) + } + return output +} diff --git a/client/build/vue-loader.conf.js b/client/build/vue-loader.conf.js new file mode 100644 index 0000000..7aee79b --- /dev/null +++ b/client/build/vue-loader.conf.js @@ -0,0 +1,12 @@ +var utils = require('./utils') +var config = require('../config') +var isProduction = process.env.NODE_ENV === 'production' + +module.exports = { + loaders: utils.cssLoaders({ + sourceMap: isProduction + ? config.build.productionSourceMap + : config.dev.cssSourceMap, + extract: isProduction + }) +} diff --git a/client/build/webpack.base.conf.js b/client/build/webpack.base.conf.js new file mode 100644 index 0000000..c3930d9 --- /dev/null +++ b/client/build/webpack.base.conf.js @@ -0,0 +1,58 @@ +var path = require('path') +var utils = require('./utils') +var config = require('../config') +var vueLoaderConfig = require('./vue-loader.conf') + +function resolve (dir) { + return path.join(__dirname, '..', dir) +} + +module.exports = { + entry: { + app: './src/main.js' + }, + output: { + path: config.build.assetsRoot, + filename: '[name].js', + publicPath: process.env.NODE_ENV === 'production' + ? config.build.assetsPublicPath + : config.dev.assetsPublicPath + }, + resolve: { + extensions: ['.js', '.vue', '.json'], + alias: { + 'vue$': 'vue/dist/vue.esm.js', + '@': resolve('src'), + } + }, + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue-loader', + options: vueLoaderConfig + }, + { + test: /\.js$/, + loader: 'babel-loader', + include: [resolve('src'), resolve('test')] + }, + { + test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, + loader: 'url-loader', + query: { + limit: 10000, + name: utils.assetsPath('img/[name].[hash:7].[ext]') + } + }, + { + test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, + loader: 'url-loader', + query: { + limit: 10000, + name: utils.assetsPath('fonts/[name].[hash:7].[ext]') + } + } + ] + } +} diff --git a/client/build/webpack.dev.conf.js b/client/build/webpack.dev.conf.js new file mode 100644 index 0000000..5470402 --- /dev/null +++ b/client/build/webpack.dev.conf.js @@ -0,0 +1,35 @@ +var utils = require('./utils') +var webpack = require('webpack') +var config = require('../config') +var merge = require('webpack-merge') +var baseWebpackConfig = require('./webpack.base.conf') +var HtmlWebpackPlugin = require('html-webpack-plugin') +var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') + +// add hot-reload related code to entry chunks +Object.keys(baseWebpackConfig.entry).forEach(function (name) { + baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) +}) + +module.exports = merge(baseWebpackConfig, { + module: { + rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) + }, + // cheap-module-eval-source-map is faster for development + devtool: '#cheap-module-eval-source-map', + plugins: [ + new webpack.DefinePlugin({ + 'process.env': config.dev.env + }), + // https://github.com/glenjamin/webpack-hot-middleware#installation--usage + new webpack.HotModuleReplacementPlugin(), + new webpack.NoEmitOnErrorsPlugin(), + // https://github.com/ampedandwired/html-webpack-plugin + new HtmlWebpackPlugin({ + filename: 'index.html', + template: 'index.html', + inject: true + }), + new FriendlyErrorsPlugin() + ] +}) diff --git a/client/build/webpack.prod.conf.js b/client/build/webpack.prod.conf.js new file mode 100644 index 0000000..e2f71bd --- /dev/null +++ b/client/build/webpack.prod.conf.js @@ -0,0 +1,120 @@ +var path = require('path') +var utils = require('./utils') +var webpack = require('webpack') +var config = require('../config') +var merge = require('webpack-merge') +var baseWebpackConfig = require('./webpack.base.conf') +var CopyWebpackPlugin = require('copy-webpack-plugin') +var HtmlWebpackPlugin = require('html-webpack-plugin') +var ExtractTextPlugin = require('extract-text-webpack-plugin') +var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') + +var env = process.env.NODE_ENV === 'testing' + ? require('../config/test.env') + : config.build.env + +var webpackConfig = merge(baseWebpackConfig, { + module: { + rules: utils.styleLoaders({ + sourceMap: config.build.productionSourceMap, + extract: true + }) + }, + devtool: config.build.productionSourceMap ? '#source-map' : false, + output: { + path: config.build.assetsRoot, + filename: utils.assetsPath('js/[name].[chunkhash].js'), + chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') + }, + plugins: [ + // http://vuejs.github.io/vue-loader/en/workflow/production.html + new webpack.DefinePlugin({ + 'process.env': env + }), + new webpack.optimize.UglifyJsPlugin({ + compress: { + warnings: false + }, + sourceMap: true + }), + // extract css into its own file + new ExtractTextPlugin({ + filename: utils.assetsPath('css/[name].[contenthash].css') + }), + // Compress extracted CSS. We are using this plugin so that possible + // duplicated CSS from different components can be deduped. + new OptimizeCSSPlugin(), + // generate dist index.html with correct asset hash for caching. + // you can customize output by editing /index.html + // see https://github.com/ampedandwired/html-webpack-plugin + new HtmlWebpackPlugin({ + filename: process.env.NODE_ENV === 'testing' + ? 'index.html' + : config.build.index, + template: 'index.html', + inject: true, + minify: { + removeComments: true, + collapseWhitespace: true, + removeAttributeQuotes: true + // more options: + // https://github.com/kangax/html-minifier#options-quick-reference + }, + // necessary to consistently work with multiple chunks via CommonsChunkPlugin + chunksSortMode: 'dependency' + }), + // split vendor js into its own file + new webpack.optimize.CommonsChunkPlugin({ + name: 'vendor', + minChunks: function (module, count) { + // any required modules inside node_modules are extracted to vendor + return ( + module.resource && + /\.js$/.test(module.resource) && + module.resource.indexOf( + path.join(__dirname, '../node_modules') + ) === 0 + ) + } + }), + // extract webpack runtime and module manifest to its own file in order to + // prevent vendor hash from being updated whenever app bundle is updated + new webpack.optimize.CommonsChunkPlugin({ + name: 'manifest', + chunks: ['vendor'] + }), + // copy custom static assets + new CopyWebpackPlugin([ + { + from: path.resolve(__dirname, '../static'), + to: config.build.assetsSubDirectory, + ignore: ['.*'] + } + ]) + ] +}) + +if (config.build.productionGzip) { + var CompressionWebpackPlugin = require('compression-webpack-plugin') + + webpackConfig.plugins.push( + new CompressionWebpackPlugin({ + asset: '[path].gz[query]', + algorithm: 'gzip', + test: new RegExp( + '\\.(' + + config.build.productionGzipExtensions.join('|') + + ')$' + ), + threshold: 10240, + minRatio: 0.8 + }) + ) +} + +if (config.build.bundleAnalyzerReport) { + var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin + webpackConfig.plugins.push(new BundleAnalyzerPlugin()) +} + +module.exports = webpackConfig diff --git a/client/build/webpack.test.conf.js b/client/build/webpack.test.conf.js new file mode 100644 index 0000000..8e4385c --- /dev/null +++ b/client/build/webpack.test.conf.js @@ -0,0 +1,24 @@ +// This is the webpack config used for unit tests. + +var utils = require('./utils') +var webpack = require('webpack') +var merge = require('webpack-merge') +var baseConfig = require('./webpack.base.conf') + +var webpackConfig = merge(baseConfig, { + // use inline sourcemap for karma-sourcemap-loader + module: { + rules: utils.styleLoaders() + }, + devtool: '#inline-source-map', + plugins: [ + new webpack.DefinePlugin({ + 'process.env': require('../config/test.env') + }) + ] +}) + +// no need for app entry during tests +delete webpackConfig.entry + +module.exports = webpackConfig diff --git a/client/config/dev.env.js b/client/config/dev.env.js new file mode 100644 index 0000000..efead7c --- /dev/null +++ b/client/config/dev.env.js @@ -0,0 +1,6 @@ +var merge = require('webpack-merge') +var prodEnv = require('./prod.env') + +module.exports = merge(prodEnv, { + NODE_ENV: '"development"' +}) diff --git a/client/config/index.js b/client/config/index.js new file mode 100644 index 0000000..196da1f --- /dev/null +++ b/client/config/index.js @@ -0,0 +1,38 @@ +// see http://vuejs-templates.github.io/webpack for documentation. +var path = require('path') + +module.exports = { + build: { + env: require('./prod.env'), + index: path.resolve(__dirname, '../dist/index.html'), + assetsRoot: path.resolve(__dirname, '../dist'), + assetsSubDirectory: 'static', + assetsPublicPath: '/', + productionSourceMap: true, + // Gzip off by default as many popular static hosts such as + // Surge or Netlify already gzip all static assets for you. + // Before setting to `true`, make sure to: + // npm install --save-dev compression-webpack-plugin + productionGzip: false, + productionGzipExtensions: ['js', 'css'], + // Run the build command with an extra argument to + // View the bundle analyzer report after build finishes: + // `npm run build --report` + // Set to `true` or `false` to always turn it on or off + bundleAnalyzerReport: process.env.npm_config_report + }, + dev: { + env: require('./dev.env'), + port: 8080, + autoOpenBrowser: true, + assetsSubDirectory: 'static', + assetsPublicPath: '/', + proxyTable: {}, + // CSS Sourcemaps off by default because relative paths are "buggy" + // with this option, according to the CSS-Loader README + // (https://github.com/webpack/css-loader#sourcemaps) + // In our experience, they generally work as expected, + // just be aware of this issue when enabling this option. + cssSourceMap: false + } +} diff --git a/client/config/prod.env.js b/client/config/prod.env.js new file mode 100644 index 0000000..773d263 --- /dev/null +++ b/client/config/prod.env.js @@ -0,0 +1,3 @@ +module.exports = { + NODE_ENV: '"production"' +} diff --git a/client/config/test.env.js b/client/config/test.env.js new file mode 100644 index 0000000..89f90de --- /dev/null +++ b/client/config/test.env.js @@ -0,0 +1,6 @@ +var merge = require('webpack-merge') +var devEnv = require('./dev.env') + +module.exports = merge(devEnv, { + NODE_ENV: '"testing"' +}) diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..5bff953 --- /dev/null +++ b/client/index.html @@ -0,0 +1,11 @@ + + + + + house-selling + + +
+ + + diff --git a/client/package.json b/client/package.json new file mode 100644 index 0000000..c540a1e --- /dev/null +++ b/client/package.json @@ -0,0 +1,83 @@ +{ + "name": "house-selling", + "version": "1.0.0", + "description": "A Vue.js project", + "author": "Bambang Handoko ", + "private": true, + "scripts": { + "dev": "node build/dev-server.js", + "build": "node build/build.js", + "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", + "e2e": "node test/e2e/runner.js", + "test": "npm run unit && npm run e2e" + }, + "dependencies": { + "vue": "^2.2.2", + "vue-router": "^2.2.0" + }, + "devDependencies": { + "autoprefixer": "^6.7.2", + "babel-core": "^6.22.1", + "babel-loader": "^6.2.10", + "babel-plugin-transform-runtime": "^6.22.0", + "babel-preset-env": "^1.2.1", + "babel-preset-stage-2": "^6.22.0", + "babel-register": "^6.22.0", + "chalk": "^1.1.3", + "connect-history-api-fallback": "^1.3.0", + "copy-webpack-plugin": "^4.0.1", + "css-loader": "^0.26.1", + "eventsource-polyfill": "^0.9.6", + "express": "^4.14.1", + "extract-text-webpack-plugin": "^2.0.0", + "file-loader": "^0.10.0", + "friendly-errors-webpack-plugin": "^1.1.3", + "function-bind": "^1.1.0", + "html-webpack-plugin": "^2.28.0", + "http-proxy-middleware": "^0.17.3", + "webpack-bundle-analyzer": "^2.2.1", + "cross-env": "^3.1.4", + "karma": "^1.4.1", + "karma-coverage": "^1.1.1", + "karma-mocha": "^1.3.0", + "karma-phantomjs-launcher": "^1.0.2", + "karma-sinon-chai": "^1.2.4", + "karma-sourcemap-loader": "^0.3.7", + "karma-spec-reporter": "0.0.26", + "karma-webpack": "^2.0.2", + "lolex": "^1.5.2", + "mocha": "^3.2.0", + "chai": "^3.5.0", + "sinon": "^1.17.7", + "sinon-chai": "^2.8.0", + "inject-loader": "^2.0.1", + "babel-plugin-istanbul": "^3.1.2", + "phantomjs-prebuilt": "^2.1.14", + "chromedriver": "^2.27.2", + "cross-spawn": "^5.0.1", + "nightwatch": "^0.9.12", + "selenium-server": "^3.0.1", + "semver": "^5.3.0", + "opn": "^4.0.2", + "optimize-css-assets-webpack-plugin": "^1.3.0", + "ora": "^1.1.0", + "rimraf": "^2.6.0", + "url-loader": "^0.5.7", + "vue-loader": "^11.1.4", + "vue-style-loader": "^2.0.0", + "vue-template-compiler": "^2.2.4", + "webpack": "^2.2.1", + "webpack-dev-middleware": "^1.10.0", + "webpack-hot-middleware": "^2.16.1", + "webpack-merge": "^2.6.1" + }, + "engines": { + "node": ">= 4.0.0", + "npm": ">= 3.0.0" + }, + "browserslist": [ + "> 1%", + "last 2 versions", + "not ie <= 8" + ] +} diff --git a/client/src/App.vue b/client/src/App.vue new file mode 100644 index 0000000..97c2c84 --- /dev/null +++ b/client/src/App.vue @@ -0,0 +1,23 @@ + + + + + diff --git a/client/src/assets/logo.png b/client/src/assets/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..f3d2503fc2a44b5053b0837ebea6e87a2d339a43 GIT binary patch literal 6849 zcmaKRcUV(fvo}bjDT-7nLI_nlK}sT_69H+`qzVWDA|yaU?}j417wLi^B1KB1SLsC& zL0ag7$U(XW5YR7p&Ux?sP$d4lvMt8C^+TcQu4F zQqv!UF!I+kw)c0jhd6+g6oCr9P?7)?!qX1ui*iL{p}sKCAGuJ{{W)0z1pLF|=>h}& zt(2Lr0Z`2ig8<5i%Zk}cO5Fm=LByqGWaS`oqChZdEFmc`0hSb#gg|Aap^{+WKOYcj zHjINK)KDG%&s?Mt4CL(T=?;~U@bU2x_mLKN!#GJuK_CzbNw5SMEJorG!}_5;?R>@1 zSl)jns3WlU7^J%=(hUtfmuUCU&C3%8B5C^f5>W2Cy8jW3#{Od{lF1}|?c61##3dzA zsPlFG;l_FzBK}8>|H_Ru_H#!_7$UH4UKo3lKOA}g1(R&|e@}GINYVzX?q=_WLZCgh z)L|eJMce`D0EIwgRaNETDsr+?vQknSGAi=7H00r`QnI%oQnFxm`G2umXso9l+8*&Q z7WqF|$p49js$mdzo^BXpH#gURy=UO;=IMrYc5?@+sR4y_?d*~0^YP7d+y0{}0)zBM zIKVM(DBvICK#~7N0a+PY6)7;u=dutmNqK3AlsrUU9U`d;msiucB_|8|2kY=(7XA;G zwDA8AR)VCA#JOkxm#6oHNS^YVuOU;8p$N)2{`;oF|rQ?B~K$%rHDxXs+_G zF5|-uqHZvSzq}L;5Kcy_P+x0${33}Ofb6+TX&=y;;PkEOpz%+_bCw_{<&~ zeL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cm2+kFMR)oMud1%n2=qn5nE&t@Fgr#=Zv2?}wtEz^T z9rrj=?IH*qI5{G@Rn&}^Z{+TW}mQeb9=8b<_a`&Cm#n%n~ zU47MvCBsdXFB1+adOO)03+nczfWa#vwk#r{o{dF)QWya9v2nv43Zp3%Ps}($lA02*_g25t;|T{A5snSY?3A zrRQ~(Ygh_ebltHo1VCbJb*eOAr;4cnlXLvI>*$-#AVsGg6B1r7@;g^L zFlJ_th0vxO7;-opU@WAFe;<}?!2q?RBrFK5U{*ai@NLKZ^};Ul}beukveh?TQn;$%9=R+DX07m82gP$=}Uo_%&ngV`}Hyv8g{u z3SWzTGV|cwQuFIs7ZDOqO_fGf8Q`8MwL}eUp>q?4eqCmOTcwQuXtQckPy|4F1on8l zP*h>d+cH#XQf|+6c|S{7SF(Lg>bR~l(0uY?O{OEVlaxa5@e%T&xju=o1`=OD#qc16 zSvyH*my(dcp6~VqR;o(#@m44Lug@~_qw+HA=mS#Z^4reBy8iV?H~I;{LQWk3aKK8$bLRyt$g?- +
+

{{ msg }}

+

Essential Links

+ +

Ecosystem

+ +
+ + + + + + diff --git a/client/src/main.js b/client/src/main.js new file mode 100644 index 0000000..ec10971 --- /dev/null +++ b/client/src/main.js @@ -0,0 +1,15 @@ +// The Vue build version to load with the `import` command +// (runtime-only or standalone) has been set in webpack.base.conf with an alias. +import Vue from 'vue' +import App from './App' +import router from './router' + +Vue.config.productionTip = false + +/* eslint-disable no-new */ +new Vue({ + el: '#app', + router, + template: '', + components: { App } +}) diff --git a/client/src/router/index.js b/client/src/router/index.js new file mode 100644 index 0000000..5bf9ea6 --- /dev/null +++ b/client/src/router/index.js @@ -0,0 +1,15 @@ +import Vue from 'vue' +import Router from 'vue-router' +import Hello from '@/components/Hello' + +Vue.use(Router) + +export default new Router({ + routes: [ + { + path: '/', + name: 'Hello', + component: Hello + } + ] +}) diff --git a/client/static/.gitkeep b/client/static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/client/test/e2e/custom-assertions/elementCount.js b/client/test/e2e/custom-assertions/elementCount.js new file mode 100644 index 0000000..c0d5fe0 --- /dev/null +++ b/client/test/e2e/custom-assertions/elementCount.js @@ -0,0 +1,26 @@ +// A custom Nightwatch assertion. +// the name of the method is the filename. +// can be used in tests like this: +// +// browser.assert.elementCount(selector, count) +// +// for how to write custom assertions see +// http://nightwatchjs.org/guide#writing-custom-assertions +exports.assertion = function (selector, count) { + this.message = 'Testing if element <' + selector + '> has count: ' + count + this.expected = count + this.pass = function (val) { + return val === this.expected + } + this.value = function (res) { + return res.value + } + this.command = function (cb) { + var self = this + return this.api.execute(function (selector) { + return document.querySelectorAll(selector).length + }, [selector], function (res) { + cb.call(self, res) + }) + } +} diff --git a/client/test/e2e/nightwatch.conf.js b/client/test/e2e/nightwatch.conf.js new file mode 100644 index 0000000..e9ad88f --- /dev/null +++ b/client/test/e2e/nightwatch.conf.js @@ -0,0 +1,46 @@ +require('babel-register') +var config = require('../../config') + +// http://nightwatchjs.org/getingstarted#settings-file +module.exports = { + src_folders: ['test/e2e/specs'], + output_folder: 'test/e2e/reports', + custom_assertions_path: ['test/e2e/custom-assertions'], + + selenium: { + start_process: true, + server_path: require('selenium-server').path, + host: '127.0.0.1', + port: 4444, + cli_args: { + 'webdriver.chrome.driver': require('chromedriver').path + } + }, + + test_settings: { + default: { + selenium_port: 4444, + selenium_host: 'localhost', + silent: true, + globals: { + devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port) + } + }, + + chrome: { + desiredCapabilities: { + browserName: 'chrome', + javascriptEnabled: true, + acceptSslCerts: true + } + }, + + firefox: { + desiredCapabilities: { + browserName: 'firefox', + javascriptEnabled: true, + acceptSslCerts: true + } + } + } +} diff --git a/client/test/e2e/runner.js b/client/test/e2e/runner.js new file mode 100644 index 0000000..2a5c6ef --- /dev/null +++ b/client/test/e2e/runner.js @@ -0,0 +1,31 @@ +// 1. start the dev server using production config +process.env.NODE_ENV = 'testing' +var server = require('../../build/dev-server.js') + +// 2. run the nightwatch test suite against it +// to run in additional browsers: +// 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings" +// 2. add it to the --env flag below +// or override the environment flag, for example: `npm run e2e -- --env chrome,firefox` +// For more information on Nightwatch's config file, see +// http://nightwatchjs.org/guide#settings-file +var opts = process.argv.slice(2) +if (opts.indexOf('--config') === -1) { + opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js']) +} +if (opts.indexOf('--env') === -1) { + opts = opts.concat(['--env', 'chrome']) +} + +var spawn = require('cross-spawn') +var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' }) + +runner.on('exit', function (code) { + server.close() + process.exit(code) +}) + +runner.on('error', function (err) { + server.close() + throw err +}) diff --git a/client/test/e2e/specs/test.js b/client/test/e2e/specs/test.js new file mode 100644 index 0000000..a7b1bd9 --- /dev/null +++ b/client/test/e2e/specs/test.js @@ -0,0 +1,19 @@ +// For authoring Nightwatch tests, see +// http://nightwatchjs.org/guide#usage + +module.exports = { + 'default e2e tests': function (browser) { + // automatically uses dev Server port from /config.index.js + // default: http://localhost:8080 + // see nightwatch.conf.js + const devServer = browser.globals.devServerURL + + browser + .url(devServer) + .waitForElementVisible('#app', 5000) + .assert.elementPresent('.hello') + .assert.containsText('h1', 'Welcome to Your Vue.js App') + .assert.elementCount('img', 1) + .end() + } +} diff --git a/client/test/unit/.eslintrc b/client/test/unit/.eslintrc new file mode 100644 index 0000000..959a4f4 --- /dev/null +++ b/client/test/unit/.eslintrc @@ -0,0 +1,9 @@ +{ + "env": { + "mocha": true + }, + "globals": { + "expect": true, + "sinon": true + } +} diff --git a/client/test/unit/index.js b/client/test/unit/index.js new file mode 100644 index 0000000..32f57b6 --- /dev/null +++ b/client/test/unit/index.js @@ -0,0 +1,16 @@ +import Vue from 'vue' +Vue.config.productionTip = false + +// Polyfill fn.bind() for PhantomJS +/* eslint-disable no-extend-native */ +Function.prototype.bind = require('function-bind') + +// require all test files (files that ends with .spec.js) +const testsContext = require.context('./specs', true, /\.spec$/) +testsContext.keys().forEach(testsContext) + +// require all src files except main.js for coverage. +// you can also change this to match only the subset of files that +// you want coverage for. +const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/) +srcContext.keys().forEach(srcContext) diff --git a/client/test/unit/karma.conf.js b/client/test/unit/karma.conf.js new file mode 100644 index 0000000..3211fb6 --- /dev/null +++ b/client/test/unit/karma.conf.js @@ -0,0 +1,33 @@ +// This is a karma config file. For more details see +// http://karma-runner.github.io/0.13/config/configuration-file.html +// we are also using it with karma-webpack +// https://github.com/webpack/karma-webpack + +var webpackConfig = require('../../build/webpack.test.conf') + +module.exports = function (config) { + config.set({ + // to run in additional browsers: + // 1. install corresponding karma launcher + // http://karma-runner.github.io/0.13/config/browsers.html + // 2. add it to the `browsers` array below. + browsers: ['PhantomJS'], + frameworks: ['mocha', 'sinon-chai'], + reporters: ['spec', 'coverage'], + files: ['./index.js'], + preprocessors: { + './index.js': ['webpack', 'sourcemap'] + }, + webpack: webpackConfig, + webpackMiddleware: { + noInfo: true + }, + coverageReporter: { + dir: './coverage', + reporters: [ + { type: 'lcov', subdir: '.' }, + { type: 'text-summary' } + ] + } + }) +} diff --git a/client/test/unit/specs/Hello.spec.js b/client/test/unit/specs/Hello.spec.js new file mode 100644 index 0000000..80140ba --- /dev/null +++ b/client/test/unit/specs/Hello.spec.js @@ -0,0 +1,11 @@ +import Vue from 'vue' +import Hello from '@/components/Hello' + +describe('Hello.vue', () => { + it('should render correct contents', () => { + const Constructor = Vue.extend(Hello) + const vm = new Constructor().$mount() + expect(vm.$el.querySelector('.hello h1').textContent) + .to.equal('Welcome to Your Vue.js App') + }) +}) diff --git a/server/app.js b/server/app.js new file mode 100644 index 0000000..44f714c --- /dev/null +++ b/server/app.js @@ -0,0 +1,40 @@ +var express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); +var cors = require('cors') + +var index = require('./routes/index'); + +var app = express(); + +app.use(cors()) +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', index); + +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// error handler +app.use(function(err, req, res, next) { + // set locals, only providing error in development + res.locals.message = err.message; + res.locals.error = req.app.get('env') === 'development' ? err : {}; + + // render the error page + res.status(err.status || 500); + res.render('error'); +}); + +module.exports = app; diff --git a/server/bin/www b/server/bin/www new file mode 100755 index 0000000..3ac0c8a --- /dev/null +++ b/server/bin/www @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +/** + * Module dependencies. + */ + +var app = require('../app'); +var debug = require('debug')('house-selling:server'); +var http = require('http'); + +/** + * Get port from environment and store in Express. + */ + +var port = normalizePort(process.env.PORT || '3000'); +app.set('port', port); + +/** + * Create HTTP server. + */ + +var server = http.createServer(app); + +/** + * Listen on provided port, on all network interfaces. + */ + +server.listen(port); +server.on('error', onError); +server.on('listening', onListening); + +/** + * Normalize a port into a number, string, or false. + */ + +function normalizePort(val) { + var port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; +} + +/** + * Event listener for HTTP server "error" event. + */ + +function onError(error) { + if (error.syscall !== 'listen') { + throw error; + } + + var bind = typeof port === 'string' + ? 'Pipe ' + port + : 'Port ' + port; + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } +} + +/** + * Event listener for HTTP server "listening" event. + */ + +function onListening() { + var addr = server.address(); + var bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + debug('Listening on ' + bind); +} diff --git a/server/config/config.js b/server/config/config.js new file mode 100644 index 0000000..99f8f28 --- /dev/null +++ b/server/config/config.js @@ -0,0 +1,35 @@ +'use strict' + +const mongoose = require('mongoose') +require('dotenv').config() + +// Build the connection string +var dbURI = `mongodb://${process.env.HOSTNAME}/${process.env.DATABASE_NAME}` + +// Create the database connection +mongoose.connect(dbURI) +mongoose.Promise = global.Promise + +// CONNECTION EVENTS +// When successfully connected +mongoose.connection.on('connected', () => { + console.log('Mongoose default connection open to ' + dbURI) +}) + +// If the connection throws an error +mongoose.connection.on('error', (err) => { + console.log('Mongoose default connection error: ' + err) +}) + +// When the connection is disconnected +mongoose.connection.on('disconnected', () => { + console.log('Mongoose default connection disconnected') +}) + +// If the Node process ends, close the Mongoose connection +process.on('SIGINT', () => { + mongoose.connection.close(() => { + console.log('Mongoose default connection disconnected through app termination') + process.exit(0) + }) +}) diff --git a/server/package.json b/server/package.json new file mode 100644 index 0000000..fe97a26 --- /dev/null +++ b/server/package.json @@ -0,0 +1,20 @@ +{ + "name": "house-selling", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www", + "dev": "nodemon ./bin/www" + }, + "dependencies": { + "body-parser": "~1.15.2", + "cookie-parser": "~1.4.3", + "debug": "~2.2.0", + "dotenv": "^4.0.0", + "ejs": "~2.5.2", + "express": "~4.14.0", + "morgan": "~1.7.0", + "nodemon": "^1.11.0", + "serve-favicon": "~2.3.0" + } +} diff --git a/server/routes/index.js b/server/routes/index.js new file mode 100644 index 0000000..ecca96a --- /dev/null +++ b/server/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Express' }); +}); + +module.exports = router; From 3b27c91ca6348a5855c19c46752e599019dafa78 Mon Sep 17 00:00:00 2001 From: Bambang Handoko Date: Tue, 21 Mar 2017 17:03:23 +0700 Subject: [PATCH 2/5] Vue Axios CRD --- client/index.html | 2 +- client/package.json | 1 + client/src/App.vue | 9 ++++- client/src/components/Detail.vue | 46 +++++++++++++++++++++++++ client/src/components/Hello.vue | 51 ++++++++++++++++++---------- client/src/components/House.vue | 24 +++++++++++++ client/src/components/Register.vue | 41 +++++++++++++++++++++++ client/src/router/index.js | 11 ++++++ server/app.js | 50 +++++++++++++++------------ server/controllers/house.js | 54 ++++++++++++++++++++++++++++++ server/models/Images.js | 19 +++++++++++ server/models/houses.js | 23 +++++++++++++ server/package.json | 4 ++- server/routes/index.js | 19 +++++++---- server/seeders/seeder.js | 38 +++++++++++++++++++++ 15 files changed, 343 insertions(+), 49 deletions(-) create mode 100644 client/src/components/Detail.vue create mode 100644 client/src/components/House.vue create mode 100644 client/src/components/Register.vue create mode 100644 server/controllers/house.js create mode 100644 server/models/Images.js create mode 100644 server/models/houses.js create mode 100644 server/seeders/seeder.js diff --git a/client/index.html b/client/index.html index 5bff953..a9da9bb 100644 --- a/client/index.html +++ b/client/index.html @@ -2,7 +2,7 @@ - house-selling + House Selling
diff --git a/client/package.json b/client/package.json index c540a1e..83e2130 100644 --- a/client/package.json +++ b/client/package.json @@ -12,6 +12,7 @@ "test": "npm run unit && npm run e2e" }, "dependencies": { + "axios": "^0.15.3", "vue": "^2.2.2", "vue-router": "^2.2.0" }, diff --git a/client/src/App.vue b/client/src/App.vue index 97c2c84..39af76e 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -1,6 +1,7 @@ @@ -12,6 +13,12 @@ export default { diff --git a/client/src/components/Hello.vue b/client/src/components/Hello.vue index 2d80539..eafb1a4 100644 --- a/client/src/components/Hello.vue +++ b/client/src/components/Hello.vue @@ -1,38 +1,53 @@ diff --git a/client/src/components/Register.vue b/client/src/components/Register.vue new file mode 100644 index 0000000..b0f854b --- /dev/null +++ b/client/src/components/Register.vue @@ -0,0 +1,41 @@ + + + + + diff --git a/client/src/router/index.js b/client/src/router/index.js index 5bf9ea6..aced177 100644 --- a/client/src/router/index.js +++ b/client/src/router/index.js @@ -1,6 +1,8 @@ import Vue from 'vue' import Router from 'vue-router' import Hello from '@/components/Hello' +import Detail from '@/components/Detail' +import Register from '@/components/register' Vue.use(Router) @@ -10,6 +12,15 @@ export default new Router({ path: '/', name: 'Hello', component: Hello + },{ + path: '/detail/:slug', + name: 'Detail', + props: true, + component: Detail + },{ + path: '/register', + name: 'Register', + component: Register } ] }) diff --git a/server/app.js b/server/app.js index 44f714c..73433d4 100644 --- a/server/app.js +++ b/server/app.js @@ -1,8 +1,8 @@ var express = require('express'); -var path = require('path'); -var favicon = require('serve-favicon'); +// var path = require('path'); +// var favicon = require('serve-favicon'); var logger = require('morgan'); -var cookieParser = require('cookie-parser'); +// var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var cors = require('cors') @@ -10,31 +10,37 @@ var index = require('./routes/index'); var app = express(); +// // view engine setup +// app.set('views', path.join(__dirname, 'views')); +// app.set('view engine', 'ejs'); + +// uncomment after placing your favicon in /public +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); app.use(cors()) app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); -app.use(cookieParser()); -app.use(express.static(path.join(__dirname, 'public'))); +// app.use(cookieParser()); +// app.use(express.static(path.join(__dirname, 'public'))); -app.use('/', index); +app.use('/api', index); // catch 404 and forward to error handler -app.use(function(req, res, next) { - var err = new Error('Not Found'); - err.status = 404; - next(err); -}); - -// error handler -app.use(function(err, req, res, next) { - // set locals, only providing error in development - res.locals.message = err.message; - res.locals.error = req.app.get('env') === 'development' ? err : {}; - - // render the error page - res.status(err.status || 500); - res.render('error'); -}); +// app.use(function(req, res, next) { +// var err = new Error('Not Found'); +// err.status = 404; +// next(err); +// }); +// +// // error handler +// app.use(function(err, req, res, next) { +// // set locals, only providing error in development +// res.locals.message = err.message; +// res.locals.error = req.app.get('env') === 'development' ? err : {}; +// +// // render the error page +// res.status(err.status || 500); +// res.render('error'); +// }); module.exports = app; diff --git a/server/controllers/house.js b/server/controllers/house.js new file mode 100644 index 0000000..6767b1c --- /dev/null +++ b/server/controllers/house.js @@ -0,0 +1,54 @@ +'use strict' + +const Model = require('../models/houses') +const Slug = require('slug') +const House = {} + +House.getHouses = (req, res, next) => { + Model.find({}).sort({createdAt: 'desc'}).then((houses) => { + res.send(houses) + }) +} + +House.getHouse = (req, res, next) => { + Model.findOne({ slug: req.params.slug }).then((house) => { + res.send(house) + }).catch((error) => { + res.send(error) + }) +} + +House.newHouse = (req, res, next) => { + Model.create({ + title: req.body.title, + image: req.body.image, + spesification: req.body.spesification, + price: req.body.price, + address: req.body.address, + latitude: req.body.latitude, + longitude: req.body.longitude, + slug: Slug(req.body.title).toLowerCase() + }).then((house) => { + res.send(house) + }).catch((err) => { + res.send(err) + }) +} + +House.updateHouse = (req, res, next) => { + Model.update({slug: req.params.slug}).then((house) => { + res.send(house) + }).catch((err) => { + res.send(err) + }) +} + +House.removeHouse = (req, res, next) => { + Model.remove({slug: req.params.slug}).then((house) => { + res.send(house) + }).catch((err) => { + res.send(err) + }) +} + +module.exports = House diff --git a/server/models/Images.js b/server/models/Images.js new file mode 100644 index 0000000..f44246c --- /dev/null +++ b/server/models/Images.js @@ -0,0 +1,19 @@ +'use strict' + +const mongoose = require('mongoose') +const Schema = mongoose.Schema +require('../config/config') + +let imageSchema = new Schema ({ + image1: String, + image2: String, + image3: String, + image4: String, + image5: String +}, { + timestamps: true +}) + +let Image = mongoose.model('Images', imageSchema) + +module.exports = Image diff --git a/server/models/houses.js b/server/models/houses.js new file mode 100644 index 0000000..e381d03 --- /dev/null +++ b/server/models/houses.js @@ -0,0 +1,23 @@ +'use strict' + +const mongoose = require('mongoose') +const Schema = mongoose.Schema +require('../config/config') + +let houseSchema = new Schema ({ + title: String, + image: String, + ImageId: [{ type: Schema.Types.ObjectId, ref: 'Image' }], + spesification: String, + price: String, + address: String, + latitude: String, + longitude: String, + slug: String +}, { + timestamps: true +}) + +let House = mongoose.model('Houses', houseSchema) + +module.exports = House diff --git a/server/package.json b/server/package.json index fe97a26..3de94ba 100644 --- a/server/package.json +++ b/server/package.json @@ -13,8 +13,10 @@ "dotenv": "^4.0.0", "ejs": "~2.5.2", "express": "~4.14.0", + "faker": "^4.1.0", "morgan": "~1.7.0", "nodemon": "^1.11.0", - "serve-favicon": "~2.3.0" + "serve-favicon": "~2.3.0", + "slug": "^0.9.1" } } diff --git a/server/routes/index.js b/server/routes/index.js index ecca96a..417ba91 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,9 +1,16 @@ -var express = require('express'); -var router = express.Router(); +var express = require('express') +var router = express.Router() +var House = require('../controllers/house') +var Seeder = require('../seeders/seeder') -/* GET home page. */ -router.get('/', function(req, res, next) { - res.render('index', { title: 'Express' }); -}); +router.get('/houses', House.getHouses) +router.get('/house/:slug', House.getHouse) +router.post('/house', House.newHouse) +router.put('/house/:slug', House.updateHouse) +router.delete('/house/:slug', House.removeHouse) + +// Seeder +router.post('/seedhouse', Seeder.createHouse) +router.post('/seedimage', Seeder.createImage) module.exports = router; diff --git a/server/seeders/seeder.js b/server/seeders/seeder.js new file mode 100644 index 0000000..a088fbb --- /dev/null +++ b/server/seeders/seeder.js @@ -0,0 +1,38 @@ +'use strict' + +const House = require('../models/houses') +const Image = require('../models/images') +const Faker = require('faker/locale/id_ID') +const Slug = require('slug') +const Seeder = {} + +Seeder.createHouse = (req, res, next) => { + let title = Faker.address.secondaryAddress() + + House.create({ + title: title, + image: Faker.image.city(), + spesification: Faker.lorem.sentence(), + price: Faker.commerce.price(), + address: Faker.address.streetName(), + latitude: Faker.address.latitude(), + longitude: Faker.address.longitude(), + slug: Slug(title).toLowerCase() + }).then((seeder) => { + res.send(seeder) + }) +} + +Seeder.createImage = (req, res, next) => { + Image.create({ + image1: Faker.image.city(), + image2: Faker.image.city(), + image3: Faker.image.city(), + image4: Faker.image.city(), + image5: Faker.image.city() + }).then((seeder) => { + res.send(seeder) + }) +} + +module.exports = Seeder From dff2d90a8ecd45a4fa9d6208b845d86ac31fa8be Mon Sep 17 00:00:00 2001 From: Bambang Handoko Date: Tue, 21 Mar 2017 20:23:48 +0700 Subject: [PATCH 3/5] Done --- client/src/App.vue | 8 +---- client/src/components/Edit.vue | 54 +++++++++++++++++++++++++++++++++ client/src/components/Hello.vue | 5 ++- client/src/components/House.vue | 5 ++- client/src/router/index.js | 8 ++++- server/controllers/house.js | 11 ++++++- 6 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 client/src/components/Edit.vue diff --git a/client/src/App.vue b/client/src/App.vue index 39af76e..750a0d9 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -1,7 +1,7 @@ @@ -13,12 +13,6 @@ export default { diff --git a/client/src/components/Hello.vue b/client/src/components/Hello.vue index eafb1a4..87e3154 100644 --- a/client/src/components/Hello.vue +++ b/client/src/components/Hello.vue @@ -1,6 +1,6 @@ @@ -33,6 +33,9 @@ export default { axios.delete('http://localhost:3000/api/house/' + slug).then((response) => { self.houses.splice(houseIndex, 1) }) + }, + editData(slug) { + window.location = 'http://localhost:8080/#/edit/'+ slug } }, mounted() { diff --git a/client/src/components/House.vue b/client/src/components/House.vue index cb701e7..040c15e 100644 --- a/client/src/components/House.vue +++ b/client/src/components/House.vue @@ -4,7 +4,7 @@
Tanggal Posting : {{ house.createdAt }}
Spesifikasi : {{ house.spesification }}
Harga : ${{ house.price }}
-
|
+
|
Gambar
@@ -15,6 +15,9 @@ export default { methods: { onDelete(slug) { this.$emit('delete', slug) + }, + onEdit(slug) { + this.$emit('edit', slug) } } } diff --git a/client/src/router/index.js b/client/src/router/index.js index aced177..c40582e 100644 --- a/client/src/router/index.js +++ b/client/src/router/index.js @@ -2,7 +2,8 @@ import Vue from 'vue' import Router from 'vue-router' import Hello from '@/components/Hello' import Detail from '@/components/Detail' -import Register from '@/components/register' +import Register from '@/components/Register' +import Edit from '@/components/Edit' Vue.use(Router) @@ -21,6 +22,11 @@ export default new Router({ path: '/register', name: 'Register', component: Register + },{ + path: '/edit/:slug', + name: 'Edit', + props: true, + component: Edit } ] }) diff --git a/server/controllers/house.js b/server/controllers/house.js index 6767b1c..bd23278 100644 --- a/server/controllers/house.js +++ b/server/controllers/house.js @@ -36,7 +36,16 @@ House.newHouse = (req, res, next) => { } House.updateHouse = (req, res, next) => { - Model.update({slug: req.params.slug}).then((house) => { + Model.update({slug: req.params.slug}, {$set: { + title: req.body.title, + image: req.body.image, + spesification: req.body.spesification, + price: req.body.price, + address: req.body.address, + latitude: req.body.latitude, + longitude: req.body.longitude, + slug: Slug(req.body.title).toLowerCase() + }}).then((house) => { res.send(house) }).catch((err) => { res.send(err) From 5dbfcad713c5d72a0ce3eff2605dd10c9a8be96b Mon Sep 17 00:00:00 2001 From: Bambang Handoko Date: Thu, 29 Jun 2017 23:19:19 +0700 Subject: [PATCH 4/5] Update app.js --- server/app.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/app.js b/server/app.js index 73433d4..d346a4d 100644 --- a/server/app.js +++ b/server/app.js @@ -1,6 +1,4 @@ var express = require('express'); -// var path = require('path'); -// var favicon = require('serve-favicon'); var logger = require('morgan'); // var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); From 45075f97abedc521e2dca33e3c6b067eeb9214a6 Mon Sep 17 00:00:00 2001 From: Bambang Handoko Date: Mon, 17 Jul 2017 11:55:14 +0700 Subject: [PATCH 5/5] Update app.js --- server/app.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server/app.js b/server/app.js index d346a4d..077a08a 100644 --- a/server/app.js +++ b/server/app.js @@ -8,12 +8,7 @@ var index = require('./routes/index'); var app = express(); -// // view engine setup -// app.set('views', path.join(__dirname, 'views')); -// app.set('view engine', 'ejs'); - // uncomment after placing your favicon in /public -//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); app.use(cors()) app.use(logger('dev')); app.use(bodyParser.json());