76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
/**
|
|
* 企业首页服务器
|
|
* 基于 Express.js 的 Web 服务
|
|
*/
|
|
|
|
const express = require('express');
|
|
const path = require('path');
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// 中间件
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
// 路由
|
|
app.get('/', (req, res) => {
|
|
res.sendFile(path.join(__dirname, 'views', 'index.html'));
|
|
});
|
|
|
|
// API 路由 - 获取公司信息
|
|
app.get('/api/company-info', (req, res) => {
|
|
res.json({
|
|
name: '科技创新有限公司',
|
|
slogan: '引领未来,创造价值',
|
|
founded: '2015',
|
|
employees: '500+',
|
|
location: '北京市朝阳区科技园区'
|
|
});
|
|
});
|
|
|
|
// API 路由 - 获取服务项目
|
|
app.get('/api/services', (req, res) => {
|
|
res.json([
|
|
{
|
|
id: 1,
|
|
title: '软件开发',
|
|
description: '提供企业级软件定制开发服务',
|
|
icon: '💻'
|
|
},
|
|
{
|
|
id: 2,
|
|
title: '云计算服务',
|
|
description: '安全可靠的云端解决方案',
|
|
icon: '☁️'
|
|
},
|
|
{
|
|
id: 3,
|
|
title: '数据分析',
|
|
description: '大数据分析与商业智能',
|
|
icon: '📊'
|
|
},
|
|
{
|
|
id: 4,
|
|
title: '技术咨询',
|
|
description: '专业的技术架构咨询服务',
|
|
icon: '💡'
|
|
}
|
|
]);
|
|
});
|
|
|
|
// 错误处理
|
|
app.use((err, req, res, next) => {
|
|
console.error(err.stack);
|
|
res.status(500).json({ error: '服务器内部错误' });
|
|
});
|
|
|
|
// 启动服务器
|
|
app.listen(PORT, () => {
|
|
console.log(`🚀 服务器运行在 http://localhost:${PORT}`);
|
|
console.log(`📁 静态文件目录: ${path.join(__dirname, 'public')}`);
|
|
});
|
|
|
|
module.exports = app;
|