You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I fllow the lesson: 7.Fetching Data for Pages, i make a simple api like this:
// server.jsconstexpress=require('express');constbodyParser=require('body-parser');constnext=require('next');constdev=process.env.NODE_ENV!=='production';constapp=next({ dev });consthandle=app.getRequestHandler();constcors=require('cors');varuser=require('./controller/user.controller.js');// orm sequelizeapp.prepare().then(()=>{constserver=express();server.use(bodyParser.json());// for parsing application/jsonserver.use(bodyParser.urlencoded({extended: true}));// for parsing application/x-www-form-urlencodedserver.use(cors());server.get('/api/v1/user',(req,res)=>{user.findAll(req,res);});server.get('*',(req,res)=>{returnhandle(req,res)});server.listen(3000,(err)=>{if(err)throwerrconsole.log('> Ready on http://localhost:3000')});}).catch((ex)=>{console.error(ex.stack)process.exit(1)});
// pages/index.jsimportHeaderfrom'../components/Header';importaxiosfrom'axios';importReact,{Component}from'react';importReactDOMfrom'react-dom';// class styleexportdefaultclassIndexextendsComponent{staticasyncgetInitialProps(){try{constres=awaitaxios.get('http://localhost:3000/api/v1/user');const{ data }=res;console.log(`User data fetched.`)return{users: data||[]}}catch(error){console.log(error)return{users: []}}}render(){lethtml=this.props.users.map(user=>{return(<divclassName="user"><h5>{user.id}</h5><p>{user.firstName}</p><div>{user.lastName}</div></div>)});return(<div><Header/><p>Hello Next.js</p><div>{html}</div><stylejsxglobal>{` p{ font-size: 14px; } .user{ border-bottom: 1px solid black; background: url('./static/kitty.png') no-repeat; } `}</style></div>)}}
I fllow the lesson: 7.Fetching Data for Pages, i make a simple api like this:
why error ?
The text was updated successfully, but these errors were encountered: