Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- "start": "babel-node buildScripts/srcServer.js"
- ...
- /* eslint-disable */
- import express from 'express'
- import path from 'path'
- import opn from 'opn'
- import bodyParser from 'body-parser'
- import historyApiFallback from 'connect-history-api-fallback'
- import WebpackDevMiddleware from 'webpack-dev-middleware'
- import WebpackHotMiddleware from 'webpack-hot-middleware'
- import WebpackConfig from '../webpack.config'
- import webpack from 'webpack'
- const compiler = webpack(WebpackConfig)
- const app = express()
- const port = 8080
- app.use(historyApiFallback({
- verbose: false
- }))
- app.use(WebpackDevMiddleware(compiler, {
- publicPath: WebpackConfig.output.publicPath,
- hot: true,
- quiet: false,
- noInfo: false,
- lazy: false,
- stats: {
- colors: true
- }
- }))
- app.use(WebpackHotMiddleware(compiler))
- app.use(bodyParser.urlencoded({ extended: false}))
- app.use(bodyParser.json())
- app.use('*', function (req, res, next) {
- console.log(req.url)
- var filename = path.join(compiler.outputPath,'login/login.html');
- compiler.outputFileSystem.readFile(filename, function(err, result){
- if (err) {
- return next(err);
- }
- res.set('content-type','text/html');
- res.send(result);
- res.end();
- });
- });
- require('dotenv').config()
- const mongoose = require('mongoose')
- const User = require('../models/User')
- mongoose.connect(process.env.DATABASE);
- mongoose.Promise = global.Promise;
- mongoose.connection
- .on('connected', () => {
- console.log(`Mongoose connection open on ${process.env.DATABASE}`);
- })
- .on('error', (err) => {
- console.log(`Connection error: ${err.message}`);
- });
- mongoose.model('User')
- app.get('/users', function (req, res) {
- User.find().lean().exec(function (err, users) {
- return res.end(JSON.stringify(users));
- })
- })
- app.get('/questions', function (req, res) {
- res.json([
- { 'id':1, 'header': 'Qheader', 'question': 'Question', 'description': 'Description' },
- { 'id':2, 'header': 'Qheader1', 'question': 'Question1', 'description': 'Description1' }
- ])
- })
- // set up routing
- app.get('/', function (req, res) {
- res.sendFile(path.join(__dirname, '../dist/login/login.html'))
- })
- app.get('/dashboard', function (req, res) {
- res.sendFile(path.join(__dirname, '../dist/dashboard/dashboard.html'))
- })
- app.get('/assessments', function (req, res) {
- res.sendFile(path.join(__dirname, '../dist/assessments/assessments.html'))
- })
- app.get('/registration', function (req, res) {
- res.sendFile(path.join(__dirname, '../dist/registration/registration.html'))
- })
- app.get('/success', function (req, res) {
- res.sendFile(path.join(__dirname, '../dist/responses/success.html'))
- })
- app.post('/registerUser', function (req, res) {
- var user=new User({
- name:req.body.uname,
- uname:req.body.email,
- pass:req.body.pass
- })
- user.save().then(item => {
- console.log('success')
- res.send("success")
- }).catch(err => {
- console.log('fail')
- res.status(400).send("failure")
- })
- })
- // set up listening
- app.listen(port, function (err) {
- if (err) {
- console.log(err)
- } else {
- opn('http://localhost:' + port)
- }
- })
- const path = require('path')
- const webpack = require('webpack')
- const HtmlWebpackPlugin = require('html-webpack-plugin')
- const CopyWebpackPlugin = require('copy-webpack-plugin')
- module.exports = {
- mode: 'development',
- entry: [
- 'webpack-hot-middleware/client?http://localhost:8080&timeout=20000', './src/login/app.js'
- ],
- target: 'web',
- output: {
- path: path.resolve(__dirname, 'dist'),
- publicPath: '/',
- filename: 'bundle.js'
- },
- plugins: [
- new webpack.HotModuleReplacementPlugin(),
- new CopyWebpackPlugin([
- {
- from: './src/images/',
- to: 'images/',
- force: true
- },
- {
- from: './node_modules/bootstrap/fonts/',
- to: 'node_modules/bootstrap/fonts/',
- force: true
- }
- ]),
- new HtmlWebpackPlugin({
- filename: 'login/login.html',
- template: './src/login/login.html',
- inject: true
- }),
- new HtmlWebpackPlugin({
- filename: 'dashboard/dashboard.html',
- template: './src/dashboard/dashboard.html',
- inject: true
- }),
- new HtmlWebpackPlugin({
- filename: 'assessments/assessments.html',
- template: './src/assessments/assessments.html',
- inject: true
- }),
- new webpack.ProvidePlugin({
- $: 'jquery',
- jQuery: 'jquery'
- })
- ],
- module: {
- rules: [
- {
- test: /.css$/,
- use: ['style-loader', 'css-loader']
- },
- {
- test: /.(eot|svg|ttf|woff|woff2)$/,
- use: {
- loader: 'file-loader',
- options: {
- name: '../../node_modules/bootstrap/fonts/[name].[ext]'
- }
- }
- },
- {
- test: /.(png|jpg)$/,
- use: {
- loader: 'file-loader',
- options: {
- name: '../images/[name].[ext]'
- }
- }
- },
- {
- test: /.(html)$/,
- use: {
- loader: 'html-loader',
- options: {
- name: '../*/[name].[ext]'
- }
- }
- }
- ]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement