Answer the question
In order to leave comments, you need to log in
How to address requests if they are ignored, the only request is to index.html?
I'm using webpack-dev-middleware , and accessing index.html like this:
app.get('/*',(req,res)=>{
res.sendFile(path.join(__dirname,'./public/index.html'));
});
router.get('/list',(req,res)=>{
...
});
router.post('/create',(req,res)=>{
...
});
router.delete('/del/:id',(req,res)=>{
....
});
export default router;
app.use('/*',api);
import api from './server/routers/index.js';
import webpack from 'webpack';
import webpackDev from 'webpack-dev-middleware';
import webpackHot from 'webpack-hot-middleware';
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use(webpackDev(compiler,{
stats:{
colors: true
}
}))
app.use(webpackHot(compiler));
app.use('/*',api);
app.get('/*',(req,res)=>{
res.sendFile(path.join(__dirname,'./public/index.html'));
});
import express from 'express';
import * as api from './api.js';
const router = express.Router();
router.get('/list',(req,res)=>{
api.listNote()
.then(data=>res.status(200).send(data))
.catch(err=>res.status(500).send());
});
router.post('/create',(req,res)=>{
api.createNote(req.body)
.then(data=>res.status(200).send(data))
.catch(err=>res.status(500).send());
});
router.delete('/del/:id',(req,res)=>{
api.deleteNote(req.params.id)
.then(data=>res.status(200).send(data))
.catch(err=>res.status(500).send());
});
export default router;
import mongoose from 'mongoose';
import '../models/note.js';
const Note = mongoose.model('note');
export function listNote(){
return Note.find();
}
export function createNote(data){
const note = new Note({
title:data.title,
color:data.color,
text:data.text,
createAt:new Date()
});
return note.save();
}
export function deleteNote(id){
return Note.find({_id:id}).remove().exec();
}
Answer the question
In order to leave comments, you need to log in
With this entry,
you intercept all the paths `/...` and give index along them.
You can put it in index.js (well, remove the interception in server.js - I vanguy that the first code example is called that)
router.get('/',(req,res)=>{
res.sendFile(path.join(__dirname,'./public/index.html'));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question