2018-03-07-01

1. 删除index.html和yarn-error.log 删除server文件夹下的index.js 并将server.js重命名为index.js

2."scripts": { "dev": "babel-node server/server.js --presets env,react", "build-ssr": "webpack --config ./webpack.config.ssr.js", "build-serve": "babel server/server.js --out-file server/index.js --presets env,react", "start": "node server/index.js" }, 3.server.js { const express = require('express'); const path = require('path'); const React = require('react'); const ejs = require('ejs'); const bodyParser = require('body-parser'); const webpack = require('webpack'); const webpackConfig = require('../webpack.config'); const {handleBlog,handleLabel,handleKeyword,handleArticle,handleInsert,handleDelete,handleUpdate} = require('./routes'); const render = require('../build/ssr');

const app = express(); const jsonParser = bodyParser.json(); const compiler = webpack(webpackConfig); const port = process.env.PORT || 3000;

app.use(require('webpack-dev-middleware')(compiler, { noInfo: true, publicPath:'/static/' })); app.use('/public',express.static(path.join(dirname,'public'))); app.set('views',dirname + '/views'); app.set('view engine','ejs');

app.get('/',render.default); app.get('/article',handleArticle); app.get('/label',handleLabel); app.get('/keyword',handleKeyword);

app.get('/blog/:year/:month/:article',handleBlog);

app.post(/^\/preview$|^\/article$/,jsonParser,handleInsert);

app.delete(/^\/preview$|^\/article$/,jsonParser,handleDelete);

app.put(/^\/preview$|^\/article$/,jsonParser,handleUpdate);

app.listen(port,() => console.log("express server listening on port " + port)); } 4.访问问题和添加评论

JSRUN前端笔记, 是针对前端工程师开放的一个笔记分享平台,是前端工程师记录重点、分享经验的一个笔记本。JSRUN前端采用的 MarkDown 语法 (极客专用语法), 这里只属于前端工程师。