In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the details of server startup of full-stack CMS system". In daily operation, I believe many people have doubts about the details of server startup of full-stack CMS system. I have consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "what are the details of server startup of full-stack CMS system?" Next, please follow the editor to study!
Installation of 1.redis and startup of redis server
We can go to the redis official website to download the redis installer, I mainly introduce the installation of window and linux systems, if you are other systems, you can go to the official website to check the relevant information.
Install and start the service under 1.window
Download address: https://github.com/MSOpenTech/redis/releasesRedis supports 32-bit and 64-bit. This needs to be selected according to your system platform, download the zip file to disk C, extract it and rename the folder to redis. (this is a convenient place to remember)
Open a cmd window and use the cd command to change directories to C:\ redis, and then run:
Redis-server.exe redis.windows.conf
After input, if the following interface is displayed, the startup is successful:
Of course, we can also add the redis path to the environment variable so that we don't have to execute the script under the redis path every time. If we want to test whether redis can be executed, the cmd window we launched above must not be closed, otherwise we will get the following error when we run node:
All right, let's go ahead and test if redis is available. First, let's create a new cmd window and change to the redis directory to run it:
Redis-cli.exe-h 127.0.0.1-p 6379
Set key-value pairs:
Set user xxx
The result is as follows:
In this way, redis can start this piece.
Install and start redis under 2.linux
Download address: http://redis.io/download, it is recommended to download the latest stable version.
$wget http://download.redis.io/releases/redis-2.8.17.tar.gz $tar xzf redis-2.8.17.tar.gz $cd redis-2.8.17$ make
After make, the compiled redis service program redis-server appears in the redis-2.8.17 directory, and the client program redis-cli is used for testing. The two programs are located in the installation directory src directory. Start the redis service below:
$cd src $. / redis-server
Then the way to use redis-cli is similar to window, so I won't give an example here. If you want to learn more about the configuration and startup of redis, please read the official redis documentation carefully.
Startup of 2.node server and configuration of development environment and formal environment
I also briefly talked about the compilation and configuration of node in the previous article, here we specifically describe how to start the project and package online and release the environment code. First, let's take a look at the execution code of package.json:
"scripts": {"start": "export NODE_ENV=development & & nodemon-w src-- exec\" babel-node src\ "," build ":" babel src-- out-dir dist "," run-build ":" node dist "," test ":" echo\ "Error: no test specified\" & & exit 1 "}
Let's first take a look at start, which is mainly used to start the server of our development environment. We define the environment variables of the development environment through export NODE_ENV=development. Since I am using a mac computer, we can use export to define a node environment variable; under window, we use set NODE_ENV=development to define. We start it with the following instructions:
Npm start / / or yarn start
Secondly, let's take a look at the build command, which is mainly the output command. Dist is the directory name of the output, and you can also name it according to your own code style. We implement the following package:
Npm run build / / or yarn build
I added the run-build command, mainly the code that facilitates testing the production environment, that is, the post-code that we packaged. The mode of execution is the same as above. On how to use environment variables, here we can refer to the code under config in my project:
Const isDev = process.env.NODE_ENV = = 'development'; / / get the native ip address function getIPAdress () {var interfaces = require (' os'). NetworkInterfaces (); for (var devName in interfaces) {var iface = interfaces [devName]; for (var I = 0; I < iface.length; iTunes +) {var alias = iface [I] If (alias.family = = 'IPv4' & & alias.address! =' 127.0.0.1'& &! alias.internal) {return alias.address;} const IP = getIPAdress (); const staticPath = isDev? `address: 'online address'; module.exports = {isDev, staticPath}
We can use process.env.NODE_ENV to get the environment variables we defined under package and do different operations. The main function of the above code is to pass environment variables under other business codes and use different ip addresses for static paths according to different environments to facilitate front and rear debugging.
3. Testing the server interface and using postman to test the interface
When we start the server, we can use ip to test the port. Because we initialize config and admin data, we can use postman to test the reliability of the interface. For ease of understanding, I will cut out the initialization code and communicate with you if you don't understand.
/ / server/src/db/schema/config.js / /... / / initialize config data async function initConfig () {const isExist = await configSchema.exists () if (! isExist) {const result = await configSchema.hmset (null, {header: {columns: ['Home'], height:'50%, backgroundColor:'# 000000' Logo:''}, banner: {type: '1percent, / / 0 is the tag cloud 1 is label: [], bgUrl:'', bannerList: []}, bannerSider: {tit: 'sidebar information', imgUrl:'', desc:''} SupportPay: {tit:', imgUrl:'}) if (! Array.isArray (result)) {console.log ('configuration information initialization completed')} else {throw result}} initConfig ()
We can see this code initializing config under server/src/db/schema/config.js, and then look at the route definition:
We find server/src/routes/config.js, where we use modifiers and class to define our routing api path as / api/v0/config/all. Since our service runs on port 3000, we use postman to access:
In this way, do you have the initialization data that we defined earlier?
At this point, the study on "what are the details of server startup of full-stack CMS system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.