### Install asynckit Package
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/asynckit/README.md
Shows how to install the asynckit package using npm. This is the standard way to add the library to your project.
```sh
$ npm install --save asynckit
```
--------------------------------
### Build Frontend for Production
Source: https://github.com/zishu-co/jobscouter/blob/main/README_mac.md
Navigates to the frontend directory, installs Node.js dependencies using npm, and builds the production-ready static assets for deployment.
```bash
# 进入前端目录
cd frontend
# 安装依赖
npm install
# 构建生产环境代码
npm run build
```
--------------------------------
### Start Backend and Frontend Services
Source: https://github.com/zishu-co/jobscouter/blob/main/README.md
Commands to start the backend FastAPI application and the frontend development server. For production, the frontend build artifacts should be served by a web server like Nginx.
```bash
# 启动后端服务
cd backend
python job_request.py
# 启动前端服务(开发环境)
cd frontend
npm run dev
# 或使用生产环境部署
# 将 frontend/dist 目录下的文件部署到 Nginx 等 Web 服务器
```
--------------------------------
### Install Chrome and ChromeDriver
Source: https://github.com/zishu-co/jobscouter/blob/main/README.md
Steps to download and install Google Chrome and ChromeDriver on a Linux system. It's crucial to ensure the ChromeDriver version matches the installed Chrome browser version.
```bash
# 安装Python 3.8+
# 安装Chrome浏览器
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
# 安装ChromeDriver
# 注意版本要与Chrome浏览器版本匹配
wget https://chromedriver.storage.googleapis.com/[version]/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/local/bin/
```
--------------------------------
### Deploy Jobscouter Project
Source: https://github.com/zishu-co/jobscouter/blob/main/README.md
Instructions for deploying the jobscouter project. This includes cloning the repository, creating and activating a Python virtual environment, and installing project dependencies from requirements.txt.
```bash
# 克隆项目
git clone [项目地址]
cd [项目目录]
# 创建虚拟环境
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
# 安装依赖
pip install -r requirements.txt
# 配置邮箱
cp .env.example .env
# 编辑 .env 文件,填入邮箱配置
```
--------------------------------
### Install proxy-from-env
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/proxy-from-env/README.md
Installs the proxy-from-env package using npm. This is the first step to integrate the library into your Node.js project.
```shell
npm install proxy-from-env
```
--------------------------------
### Start Jobscouter Frontend Service (Development)
Source: https://github.com/zishu-co/jobscouter/blob/main/README_mac.md
Starts the Vue.js development server for the frontend, allowing for real-time updates and testing during development.
```shell
# 启动前端服务(开发环境)
cd ../frontend
npm run dev
```
--------------------------------
### Install Axios with Yarn
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Installs the Axios library using the Yarn package manager. This command is equivalent to the npm install command for Yarn users.
```bash
$ yarn add axios
```
--------------------------------
### Get Buffer Example
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/form-data/Readme.md
Demonstrates how to create a FormData object, append data including a Buffer and a file, and retrieve the complete request package as a Buffer.
```javascript
var form = new FormData();
form.append( 'my_buffer', Buffer.from([0x4a,0x42,0x20,0x52,0x6f,0x63,0x6b,0x73]) );
form.append( 'my_file', fs.readFileSync('/foo/bar.jpg') );
axios.post( 'https://example.com/path/to/api',
form.getBuffer(),
form.getHeaders()
)
```
--------------------------------
### Build Frontend Application
Source: https://github.com/zishu-co/jobscouter/blob/main/README.md
Steps to build the frontend application for production. This involves navigating to the frontend directory, installing Node.js dependencies using npm, and running the build script.
```bash
# 进入前端目录
cd frontend
# 安装依赖
npm install
# 构建生产环境代码
npm run build
```
--------------------------------
### Start Jobscouter Backend Service
Source: https://github.com/zishu-co/jobscouter/blob/main/README_mac.md
Starts the FastAPI backend application, typically named 'job_request.py', which handles job searching and subscription logic.
```python
# 启动后端服务
cd backend
python job_request.py
```
--------------------------------
### Prepare Python Environment with Conda
Source: https://github.com/zishu-co/jobscouter/blob/main/README_mac.md
Sets up a Python 3.8 virtual environment using Conda, installs Google Chrome, and installs ChromeDriver, ensuring compatibility between browser and driver.
```bash
# 安装Python 3.8+,建议使用miniconda创建虚拟环境
# 安装miniconda后,新建并激活环境
conda create -n job_search python=3.8
conda activate job_search
# 安装或更新Chrome浏览器
# 可以通过Homebrew安装:
brew install --cask google-chrome
# 或前往Google官方页面下载并安装Chrome
# 安装ChromeDriver
# 注意ChromeDriver版本要与Chrome浏览器版本匹配
brew install chromedriver
# 如果需要特定版本,可直接从官网或其他渠道下载
# 下载后将chromedriver放置到 /usr/local/bin 或其他PATH目录
```
--------------------------------
### Install form-data
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/form-data/Readme.md
Installs the form-data package as a dependency for your Node.js project using npm.
```bash
npm install --save form-data
```
--------------------------------
### Install Axios with pnpm
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Installs the Axios library using the pnpm package manager. This command is the pnpm equivalent for adding Axios to a project.
```bash
$ pnpm add axios
```
--------------------------------
### Environment Preparation (Miniconda)
Source: https://github.com/zishu-co/jobscouter/blob/main/README_mac.md
Alternative instructions for setting up the Python 3.8 environment using Miniconda and activating it, along with installing Chrome and ChromeDriver via Homebrew.
```bash
# 使用 Miniconda 创建 Python 3.8 环境并激活(请确保已安装 Miniconda)
conda create -n job_search python=3.8
conda activate job_search
# 安装 Google Chrome 浏览器(推荐使用 Homebrew)
brew install --cask google-chrome
# 安装 ChromeDriver(注意版本要与 Chrome 浏览器版本匹配)
brew install --cask chromedriver
```
--------------------------------
### Install mime-db Package
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/mime-db/README.md
Installs the mime-db Node.js package using npm. This is the primary way to use the database in a Node.js environment.
```bash
npm install mime-db
```
--------------------------------
### Project Deployment (Conda Environment)
Source: https://github.com/zishu-co/jobscouter/blob/main/README_mac.md
Details project deployment steps when using a Conda environment, including cloning, dependency installation, and environment variable configuration.
```bash
# 克隆项目
git clone [项目地址]
cd [项目目录]
# 注意:使用 conda 环境时,无需额外创建虚拟环境,确保已激活 job_search 环境
# 安装依赖
pip install -r requirements.txt
# 配置邮箱
cp .env.example .env
# 编辑 .env 文件,填入正确的邮箱 SMTP 配置
# 填写ai.js文件中的API_KEY
```
--------------------------------
### Install combined-stream using npm
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/combined-stream/Readme.md
Shows how to install the combined-stream package using the npm package manager. This is the first step before using the library in a Node.js project.
```bash
npm install combined-stream
```
--------------------------------
### Submit Form Example
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/form-data/Readme.md
Illustrates submitting a form with string data to a URL and handling the response.
```javascript
var form = new FormData();
form.append( 'my_string', 'Hello World' );
form.submit( 'http://example.com/', function(err, res) {
// res – response object (http.IncomingMessage) //
res.resume();
} );
```
--------------------------------
### Jobscouter System Configuration and Operation Notes
Source: https://github.com/zishu-co/jobscouter/blob/main/README.md
Important notes and considerations for running the Jobscouter system, including version compatibility, email configuration, process management, and reverse proxy setup.
```APIDOC
Jobscouter System Notes:
1. **Version Compatibility**:
- Ensure Chrome browser and ChromeDriver versions are compatible.
2. **Email Configuration**:
- Configure correct SMTP server details in the `.env` file.
3. **Process Management**:
- Recommended to use tools like `supervisor` to manage the backend process.
4. **Production Deployment**:
- Recommended to use Nginx as a reverse proxy for production.
5. **Scheduled Tasks**:
- The scheduler defaults to running every hour. Adjustments can be made in `scheduler.py`.
```
--------------------------------
### Deploy Jobscouter Project
Source: https://github.com/zishu-co/jobscouter/blob/main/README_mac.md
Clones the project repository, activates the Conda environment, installs project dependencies using pip, and configures environment variables for email settings.
```bash
# 克隆项目
git clone [项目地址]
cd [项目目录]
# 确保已在 job_search 虚拟环境中
conda activate job_search
# 安装依赖
pip install -r requirements.txt
# 配置邮箱
cp .env.example .env
# 编辑 .env 文件,填入邮箱配置
```
--------------------------------
### Basic GET Request with Axios
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Demonstrates how to make a GET request using Axios, handling success and error responses. It shows both query parameter and path-based URL fetching.
```js
import axios from 'axios';
//const axios = require('axios'); // legacy way
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
// Optionally the request above could also be done as
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
// always executed
});
// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}
```
--------------------------------
### Install Axios with npm
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Installs the Axios library using the npm package manager. This is the primary method for integrating Axios into Node.js or browser projects managed with npm.
```bash
$ npm install axios
```
--------------------------------
### Express Server for URLencoded Data
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
An example Express.js server setup using `body-parser` to handle `application/x-www-form-urlencoded` data, demonstrating how nested objects are received on the server.
```javascript
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
app.post('/', function (req, res, next) {
// echo body as JSON
res.send(JSON.stringify(req.body));
});
server = app.listen(3000);
```
--------------------------------
### Install uuid Package
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/uuid/README.md
Installs the uuid package using npm. This is the first step to using the library in your project.
```shell
npm install uuid
```
--------------------------------
### Install mime-types
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/mime-types/README.md
Installs the mime-types package using npm. This is a standard Node.js module available through the npm registry.
```sh
$ npm install mime-types
```
--------------------------------
### Install delayed-stream using npm
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/delayed-stream/Readme.md
Installs the delayed-stream package using npm. This is the standard way to add the library to your project.
```bash
npm install delayed-stream
```
--------------------------------
### Basic HTTP GET Request
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/follow-redirects/README.md
Demonstrates how to use the http.get method from follow-redirects to fetch data from a URL that might redirect. It shows how to handle response data and errors.
```javascript
const { http, https } = require('follow-redirects');
http.get('http://bit.ly/900913', response => {
response.on('data', chunk => {
console.log(chunk);
});
}).on('error', err => {
console.error(err);
});
```
--------------------------------
### Jobscouter Common Issues and Troubleshooting
Source: https://github.com/zishu-co/jobscouter/blob/main/README.md
A guide to common problems encountered with the Jobscouter system, including ChromeDriver startup failures, email sending issues, and scheduled task execution problems, along with their solutions.
```APIDOC
Jobscouter Common Issues:
1. **ChromeDriver Startup Failure**:
- **Cause**: Mismatched versions between Chrome browser and ChromeDriver.
- **Solution**: Verify and ensure both versions are identical.
- **Cause**: Insufficient system permissions.
- **Solution**: Check and grant appropriate permissions.
2. **Email Sending Failure**:
- **Cause**: Incorrect SMTP configuration.
- **Solution**: Double-check SMTP server, port, username, and password in `.env`.
- **Cause**: Email account's SMTP service is not enabled.
- **Solution**: Enable SMTP service in the email provider's settings.
3. **Scheduled Task Not Executing**:
- **Cause**: Program is not running or has crashed.
- **Solution**: Check system logs for errors and ensure the backend process is active.
- **Cause**: Scheduler configuration issues.
- **Solution**: Review the scheduler configuration in the relevant Python files.
```
--------------------------------
### Registration Success and Welcome UI
Source: https://github.com/zishu-co/jobscouter/blob/main/backend/jobDetail.txt
HTML elements indicating successful registration and guiding the user to complete their profile, including a countdown timer.
```HTML
```
--------------------------------
### Get Proxy URL for a URL
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/proxy-from-env/README.md
Demonstrates how to use the getProxyForUrl function to obtain the proxy URL for a given target URL. It shows how to handle proxied and direct requests based on environment variable configurations.
```javascript
var http = require('http');
var parseUrl = require('url').parse;
var getProxyForUrl = require('proxy-from-env').getProxyForUrl;
var some_url = 'http://example.com/something';
// // Example: Set http_proxy environment variable
// process.env.http_proxy = 'http://10.0.0.1:1234';
//
// // Example: Exclude a host from proxying
// process.env.no_proxy = 'example.com';
var proxy_url = getProxyForUrl(some_url); // Get the proxy URL
var httpOptions;
if (proxy_url) {
// Configure request to go through the proxy
var parsed_some_url = parseUrl(some_url);
var parsed_proxy_url = parseUrl(proxy_url);
httpOptions = {
protocol: parsed_proxy_url.protocol,
hostname: parsed_proxy_url.hostname,
port: parsed_proxy_url.port,
path: parsed_some_url.href,
headers: {
Host: parsed_some_url.host,
},
};
} else {
// Configure direct request
httpOptions = some_url;
}
// Make the HTTP request
http.get(httpOptions, function(res) {
var responses = [];
res.on('data', function(chunk) { responses.push(chunk); });
res.on('end', function() { console.log(responses.join('')); });
});
```
--------------------------------
### Salary Calculator Input
Source: https://github.com/zishu-co/jobscouter/blob/main/backend/jobDetail.txt
Provides an input field for users to enter their pre-tax monthly salary for calculation purposes. It includes placeholder text to guide the user.
```HTML
```
--------------------------------
### Import Axios Browser CommonJS Bundle
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Loads the Axios CommonJS bundle specifically for browser environments, useful for legacy setups or specific bundler configurations.
```javascript
const axios = require('axios/dist/browser/axios.cjs');
```
--------------------------------
### Integration with Axios (Node.js)
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/form-data/Readme.md
Provides an example of posting a file using FormData with the 'axios' library in a Node.js environment, including setting the Content-Type header.
```javascript
const form = new FormData();
const stream = fs.createReadStream(PATH_TO_FILE);
form.append('image', stream);
// In Node.js environment you need to set boundary in the header field 'Content-Type' by calling method `getHeaders`
const formHeaders = form.getHeaders();
axios.post('http://example.com', form, {
headers: {
...formHeaders,
},
})
.then(response => response)
.catch(error => error)
```
--------------------------------
### Axios Custom Adapter Example
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/lib/adapters/README.md
This JavaScript code snippet demonstrates the structure of a custom adapter for Axios. It outlines how an adapter function receives configuration, makes a request (represented by placeholders), and settles the returned Promise with a response object. It highlights the integration with Axios's core `settle` function.
```javascript
var settle = require('./../core/settle');
module.exports = function myAdapter(config) {
// At this point:
// - config has been merged with defaults
// - request transformers have already run
// - request interceptors have already run
// Make the request using config provided
// Upon response settle the Promise
return new Promise(function(resolve, reject) {
var response = {
data: responseData,
status: request.status,
statusText: request.statusText,
headers: responseHeaders,
config: config,
request: request
};
settle(resolve, reject, response);
// From here:
// - response transformers will run
// - response interceptors will run
});
}
```
--------------------------------
### Set Upload Rate Limit in Node.js with Axios
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Illustrates how to limit the upload speed for requests in Node.js environments by setting the `maxRate` option. This example also shows how to log upload progress and speed.
```javascript
const {data} = await axios.post(LOCAL_SERVER_URL, myBuffer, {
onUploadProgress: ({progress, rate}) => {
console.log(`Upload [${(progress*100).toFixed(2)}%]: ${(rate / 1024).toFixed(2)}KB/s`)
},
maxRate: [100 * 1024], // 100KB/s limit
});
```
--------------------------------
### Request Configuration Options
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
This snippet outlines the various configuration parameters available for making HTTP requests. It details options such as `url` (required), `method` (defaults to GET), `baseURL`, `headers`, `params`, `data`, `timeout`, `auth`, and `responseType`, along with their purposes and usage.
```javascript
{
// `url` is the server URL that will be used for the request
url: '/user',
// `method` is the request method to be used when making the request
method: 'get', // default
// `baseURL` will be prepended to `url` unless `url` is absolute.
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
// to methods of that instance.
baseURL: 'https://some-domain.com/api/',
// `transformRequest` allows changes to the request data before it is sent to the server
// This is only applicable for request methods 'PUT', 'POST', 'PATCH' and 'DELETE'
// The last function in the array must return a string or an instance of Buffer, ArrayBuffer,
// FormData or Stream
// You may modify the headers object.
transformRequest: [function (data, headers) {
// Do whatever you want to transform the data
return data;
}],
// `transformResponse` allows changes to the response data to be made before
// it is passed to then/catch
transformResponse: [function (data) {
// Do whatever you want to transform the data
return data;
}],
// `headers` are custom headers to be sent
headers: {'X-Requested-With': 'XMLHttpRequest'},
// `params` are the URL parameters to be sent with the request
// Must be a plain object or a URLSearchParams object
params: {
ID: 12345
},
// `paramsSerializer` is an optional config that allows you to customize serializing `params`.
paramsSerializer: {
//Custom encoder function which sends key/value pairs in an iterative fashion.
encode?: (param: string): string => { /* Do custom operations here and return transformed string */ },
// Custom serializer function for the entire parameter. Allows user to mimic pre 1.x behaviour.
serialize?: (params: Record, options?: ParamsSerializerOptions ),
//Configuration for formatting array indexes in the params.
indexes: false // Three available options: (1) indexes: null (leads to no brackets), (2) (default) indexes: false (leads to empty brackets), (3) indexes: true (leads to brackets with indexes).
},
// `data` is the data to be sent as the request body
// Only applicable for request methods 'PUT', 'POST', 'DELETE , and 'PATCH'
// When no `transformRequest` is set, must be of one of the following types:
// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
// - Browser only: FormData, File, Blob
// - Node only: Stream, Buffer, FormData (form-data package)
data: {
firstName: 'Fred'
},
// syntax alternative to send data into the body
// method post
// only the value is sent, not the key
data: 'Country=Brasil&City=Belo Horizonte',
// `timeout` specifies the number of milliseconds before the request times out.
// If the request takes longer than `timeout`, the request will be aborted.
timeout: 1000, // default is `0` (no timeout)
// `withCredentials` indicates whether or not cross-site Access-Control requests
// should be made using credentials
withCredentials: false, // default
// `adapter` allows custom handling of requests which makes testing easier.
// Return a promise and supply a valid response (see lib/adapters/README.md)
adapter: function (config) {
/* ... */
},
// Also, you can set the name of the built-in adapter, or provide an array with their names
// to choose the first available in the environment
adapter: 'xhr' // 'fetch' | 'http' | ['xhr', 'http', 'fetch']
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
// This will set an `Authorization` header, overwriting any existing
// `Authorization` custom headers you have set using `headers`.
// Please note that only HTTP Basic auth is configurable through this parameter.
// For Bearer tokens and such, use `Authorization` custom headers instead.
auth: {
username: 'janedoe',
password: 's00pers3cret'
},
// `responseType` indicates the type of data that the server will respond with
// options are: 'arraybuffer', 'document', 'json', 'text', 'stream'
// browser only: 'blob'
responseType: 'json', // default
// `responseEncoding` indicates encoding to use for decoding responses (Node.js only)
// Note: Ignored for `responseType` of 'stream' or client-side requests
// options are: 'ascii', 'ASCII', 'ansi', 'ANSI', 'binary', 'BINARY', 'base64', 'BASE64', 'base64url',
// 'BASE64URL', 'hex', 'HEX', 'latin1', 'LATIN1', 'ucs-2', 'UCS-2', 'ucs2', 'UCS2', 'utf-8', 'UTF-8',
// 'utf8', 'UTF8', 'utf16le', 'UTF16LE'
responseEncoding: 'utf8', // default
// `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
xsrfCookieName: 'XSRF-TOKEN' // default
}
```
--------------------------------
### JavaScript: Get Share Data from HTML
Source: https://github.com/zishu-co/jobscouter/blob/main/backend/jobDetail.txt
This JavaScript function retrieves share-related data (like 'shid', 'pk', 'pp') from URL query parameters and hidden input fields. It defines a helper function 'getQueryString' to parse URL parameters and then constructs a return object with the extracted values.
```javascript
function get_share_datas_from_html_inapp() {
var shid = "shdefault",
urlShid,
urlSid,
pk = "pkdefault",
pp = "ppdefault",
pkn = (typeof _PK != 'undefined' ? _PK : document.getElementById("page_key_name")),
getQueryString = function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"),
r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2])
}
return null;
};
urlShid = getQueryString("shid");
urlSid = getQueryString("sid");
if (urlShid) {
shid = urlShid;
} else if (urlSid) {
shid = urlSid;
}
if (pkn) {
var pknVal = pkn.value;
if (pknVal) {
var pkArray = pknVal.split("|");
if (pkArray.length == 1) {
pk = pkArray[0];
} else if (pkArray.length >= 2) {
pk = pkArray[0];
pp = pkArray[1];
}
}
}
var ret = [];
ret["shid"] = shid;
ret["pk"] = pk;
ret["pp"] = pp;
return ret;
}
function getQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
```
--------------------------------
### Get Length Async Example
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/form-data/Readme.md
Shows how to asynchronously get the Content-Length of the form data and set it as a request header.
```javascript
this.getLength(function(err, length) {
if (err) {
this._error(err);
return;
}
// add content length
request.setHeader('Content-Length', length);
...
}.bind(this));
```
--------------------------------
### Cancel Axios Requests with AbortController
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Starting from Axios v0.22.0, requests can be cancelled using the `AbortController` API, similar to the Fetch API. This example shows how to create a controller, attach its signal to an Axios request, and then call `abort()` to cancel the ongoing request.
```javascript
const controller = new AbortController();
axios.get('/foo/bar', {
signal: controller.signal
}).then(function(response) {
//...
});
// cancel the request
controller.abort()
```
--------------------------------
### Deploy Frontend for Production
Source: https://github.com/zishu-co/jobscouter/blob/main/README_mac.md
Instructs on deploying the built frontend assets (from the 'dist' directory) to a web server like Nginx for production use.
```shell
# 或使用生产环境部署
# 将 frontend/dist 目录下的文件部署到 Nginx 等 Web 服务器
```
--------------------------------
### Warlock Tracking Library Initialization
Source: https://github.com/zishu-co/jobscouter/blob/main/backend/error.html
Initializes the Warlock analytics tracking library with server URL, token, app name, and environment settings. It also configures auto-tracking behavior for page views and web clicks, and enables tracking for 'ka' events. The initialization is logged to the console.
```javascript
var serverUrl=isPre||isProd?"https://logapi.zhipin.com/dap/api/json":"https://logapi-dev.weizhipin.com/dap/api/json",props={server_url:serverUrl,token:"zhipin_geek_pc65A80B97CB4C27FA8F",app_name:"zhipin_web_geek_sign",auto_track_page_view:!1,auto_track_web_click:!1,track_ka:!0,env:isPre||isProd?"prod":"dev"};
try{
Warlock.init(props),
console.log("%c数星埋点初始化成功","color: #00bebd")
}catch(r){console.log("数星埋点初始化失败",r)}
```
--------------------------------
### Setting Custom Instance Axios Defaults
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Demonstrates creating Axios instances with custom default configurations, allowing for domain-specific settings and overriding global defaults.
```JavaScript
// Set config defaults when creating the instance
const instance = axios.create({
baseURL: 'https://api.example.com'
});
// Alter defaults after instance has been created
instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
```
--------------------------------
### Axios API: Creating Instances
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Allows creating a new Axios instance with custom default configurations, such as `baseURL`, `timeout`, and headers. Instance methods behave like global methods but are bound to the instance's configuration.
```js
axios.create([config])
// Example: Create an instance with custom config
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});
// Instance methods
// The specified config will be merged with the instance config.
// instance.get(url[, config])
// instance.post(url[, data[, config]])
// etc.
```
--------------------------------
### Automatic URLSearchParams Serialization
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Axios automatically serializes data to `urlencoded` format if the `content-type` header is set to `application/x-www-form-urlencoded`. This example shows nested data serialization.
```javascript
const data = {
x: 1,
arr: [1, 2, 3],
arr2: [1, [2], 3],
users: [{name: 'Peter', surname: 'Griffin'}, {name: 'Thomas', surname: 'Anderson'}],
};
await axios.postForm('https://postman-echo.com/post', data,
{headers: {'content-type': 'application/x-www-form-urlencoded'}}
);
```
--------------------------------
### WeChat Mini Program Registration HTML
Source: https://github.com/zishu-co/jobscouter/blob/main/backend/jobDetail.txt
HTML structure for the WeChat mini-program registration section, featuring a QR code display and instructions for scanning.
```HTML
```
--------------------------------
### Per-Request Options Configuration
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/follow-redirects/README.md
Details how to configure options on a per-request basis by passing an options object to the request method. This allows fine-grained control over redirect behavior, including custom logic via 'beforeRedirect'.
```javascript
const url = require('url');
const { http, https } = require('follow-redirects');
const options = url.parse('http://bit.ly/900913');
options.maxRedirects = 10;
options.beforeRedirect = (options, response, request) => {
// Use this to adjust the request options upon redirecting,
// to inspect the latest response headers,
// or to cancel the request by throwing an error
// response.headers = the redirect response headers
// response.statusCode = the redirect response code (eg. 301, 307, etc.)
// request.url = the requested URL that resulted in a redirect
// request.headers = the headers in the request that resulted in a redirect
// request.method = the method of the request that resulted in a redirect
if (options.hostname === "example.com") {
options.auth = "user:password";
}
};
http.request(options);
```
--------------------------------
### Axios API: Generic Request Configuration
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Demonstrates making HTTP requests by providing a configuration object to the main `axios` function. This allows specifying method, URL, data, and other options.
```js
axios(config)
// Example: Send a POST request
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
// Example: GET request for remote image in node.js
axios({
method: 'get',
url: 'https://bit.ly/2mTM3nY',
responseType: 'stream'
})
.then(function (response) {
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});
// Example: Send a GET request (default method)
axios('/user/12345');
```
--------------------------------
### JavaScript Analytics Script Loader
Source: https://github.com/zishu-co/jobscouter/blob/main/backend/source.txt
Initializes analytics configuration and dynamically loads the 'ka.zhipin.min.js' script. This script is responsible for client-side analytics tracking, likely for user behavior and page views.
```javascript
var _T=_T||[];!function(){
window.kaConfig={openKaToWarlockAdaptor:!0,stopAutoSendPV:!0};
var t=document.createElement("script");
t.src="https://static.zhipin.com/library/js/analytics/ka.zhipin.min.js?v=2.0";
var e=document.getElementsByTagName("script")[0];
e.parentNode.insertBefore(t,e)
}()
```
--------------------------------
### Get UUID Version
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/uuid/README.md
Detects the RFC version of a given UUID string. It returns a number representing the RFC version or throws a TypeError for invalid UUIDs.
```javascript
import { version as uuidVersion } from 'uuid';
uuidVersion('45637ec4-c85f-11ea-87d0-0242ac130003'); // ⇨ 1
uuidVersion('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨ 4
```
--------------------------------
### Axios Configuration Options
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
Details various configuration options for Axios, including HTTP parser settings, transitional behavior for JSON parsing, environment configurations, form serialization, and rate limiting.
```JavaScript
{
// Using the insecure parser should be avoided.
// see options https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_http_request_url_options_callback
// see also https://nodejs.org/en/blog/vulnerability/february-2020-security-releases/#strict-http-header-parsing-none
insecureHTTPParser: undefined, // default
// transitional options for backward compatibility that may be removed in the newer versions
transitional: {
// silent JSON parsing mode
// `true` - ignore JSON parsing errors and set response.data to null if parsing failed (old behaviour)
// `false` - throw SyntaxError if JSON parsing failed (Note: responseType must be set to 'json')
silentJSONParsing: true, // default value for the current Axios version
// try to parse the response string as JSON even if `responseType` is not 'json'
forcedJSONParsing: true,
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
clarifyTimeoutError: false,
},
env: {
// The FormData class to be used to automatically serialize the payload into a FormData object
FormData: window?.FormData || global?.FormData
},
formSerializer: {
visitor: (value, key, path, helpers) => {}; // custom visitor function to serialize form values
dots: true; // use dots instead of brackets format
metaTokens: true; // keep special endings like {} in parameter key
indexes: true; // array indexes format null - no brackets, false - empty brackets, true - brackets with indexes
},
// http adapter only (node.js)
maxRate: [
100 * 1024, // 100KB/s upload limit,
100 * 1024 // 100KB/s download limit
]
}
```
--------------------------------
### Performance Reporting Initialization
Source: https://github.com/zishu-co/jobscouter/blob/main/backend/error.html
Initializes performance reporting for the application, setting an app key based on the environment (production or development) and tracking specific user agent characteristics. It uses a try-catch block to handle potential errors during initialization.
```javascript
var isProd="prod"===window._curServerTag,isPre="pre"===window._curServerTag;
try{
performanceReport({
action:"action_js_monitor",
appKey:isProd?"ObsSRskiryhn60pf":"4Dcq7jBIr5VWWi1Q",
isAjax:!(-1
```
--------------------------------
### View Personal Competitiveness Link
Source: https://github.com/zishu-co/jobscouter/blob/main/backend/jobDetail.txt
A link to view detailed personal competitiveness analysis, triggering a JavaScript action.
```HTML
查看完整个人竞争力
```
--------------------------------
### Customize Axios Error Status with validateStatus
Source: https://github.com/zishu-co/jobscouter/blob/main/node_modules/axios/README.md
This example shows how to use the `validateStatus` configuration option to override the default behavior of rejecting responses outside the 2xx range. You can define custom logic to determine which HTTP status codes should be treated as errors.
```javascript
axios.get('/user/12345', {
validateStatus: function (status) {
return status < 500; // Resolve only if the status code is less than 500
}
})
```