News and publishing system source code
① The homepage is index. All news types and news entries are listed here.
② Each news entry has three buttons: Edit, delete, and view.
③ The homepage has a button for adding News (images can be uploaded when adding News)
The basic functions are as follows:
So we removed the routing function in the app and put all the routes in the index.
// Add the routing function to index // app. get ('/', routes. index); // app. get ('/users', user. list); routes (app );
Module. exports = function (app) {// homepage, which is now also the homepage app. get ('/', function (req, res) {res. render ('index', {title: 'express '}) ;}); app. get ('/add', function (req, res) {res. send ('add news requests');}); app. get ('/delete', function (req, res) {res. send ('delete a news request');}); app. get ('/view', function (req, res) {res. send ('view news requests');}); app. get ('/Update', function (req, res) {res. send ('modify news requests ');});};
The first step is as simple as this. Because there should be a separate page for adding news, and there will be additional processing for clicking the Add button, you have to subscribe each request internally. The rules are as follows:
/Default page. All types and news are displayed, with the delete button.
/Add To Go To The add news page
/AddNews Add the specific post request address of the News (response when the button is clicked)
/Delete: delete a news request
/View specific news Query
Then modify the preceding route slightly:
Module. exports = function (app) {// homepage, which is now also the homepage app. get ('/', function (req, res) {res. render ('index', {title: 'express '}) ;}); app. get ('/add', function (req, res) {res. send ('add news page');}); app. post ('/addnew', function (req, res) {res. send ('process and add news requests');}); app. get ('/delete', function (req, res) {res. send ('delete a news request');}); app. get ('/view', function (req, res) {res. send ('view news requests ');});};
Therefore, we need to create several templates to organize our webpage. Here we will not separate the header and tail as long as the simplest page.
Add and view template files are added, which are consistent with index. ejs and are related to modifying navigation.
Module. exports = function (app) {// homepage, which is now also the homepage app. get ('/', function (req, res) {res. render ('index', {title: 'express '}) ;}); app. get ('/add', function (req, res) {res. render ('add', {title: 'add news page'}) ;}); app. post ('/addnew', function (req, res) {res. send ('process and add news requests');}); app. get ('/delete', function (req, res) {res. send ('delete a news request');}); app. get ('/view', function (req, res) {res. render ('view', {title: 'view news requests '});});};